-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Svelte 5 migration #160
Svelte 5 migration #160
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,15 @@ | |
import { writable } from "svelte/store" | ||
import { setContext } from "svelte" | ||
import { WebsiteName } from "../../../../config" | ||
interface Props { | ||
children?: import('svelte').Snippet; | ||
} | ||
|
||
let { children }: Props = $props(); | ||
|
||
const adminSectionStore = writable("") | ||
setContext("adminSection", adminSectionStore) | ||
let adminSection: string | ||
let adminSection: string = $state() | ||
adminSectionStore.subscribe((value) => { | ||
adminSection = value | ||
}) | ||
Comment on lines
12
to
17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider simplifying state management With Svelte 5's new reactivity system using $state(), the store subscription might be redundant. Consider refactoring to use either the store or $state(), but not both. -const adminSectionStore = writable("")
-setContext("adminSection", adminSectionStore)
-let adminSection: string = $state()
-adminSectionStore.subscribe((value) => {
- adminSection = value
-})
+let adminSection: string = $state("")
+setContext("adminSection", { subscribe: () => adminSection })
|
||
|
@@ -47,12 +52,12 @@ | |
</div> | ||
</div> | ||
<div class="container px-6 lg:px-12 py-3 lg:py-6"> | ||
<slot /> | ||
{@render children?.()} | ||
</div> | ||
</div> | ||
|
||
<div class="drawer-side"> | ||
<label for="admin-drawer" class="drawer-overlay" /> | ||
<label for="admin-drawer" class="drawer-overlay"></label> | ||
<ul | ||
class="menu menu-lg p-4 w-80 min-h-full bg-base-100 lg:border-r text-primary" | ||
> | ||
|
@@ -68,7 +73,7 @@ | |
<a | ||
href="/account" | ||
class={adminSection === "home" ? "active" : ""} | ||
on:click={closeDrawer} | ||
onclick={closeDrawer} | ||
> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
|
@@ -90,7 +95,7 @@ | |
<a | ||
href="/account/billing" | ||
class={adminSection === "billing" ? "active" : ""} | ||
on:click={closeDrawer} | ||
onclick={closeDrawer} | ||
> | ||
<svg | ||
class="h-5 w-5" | ||
|
@@ -109,7 +114,7 @@ | |
<a | ||
href="/account/settings" | ||
class={adminSection === "settings" ? "active" : ""} | ||
on:click={closeDrawer} | ||
onclick={closeDrawer} | ||
> | ||
<svg class="h-5 w-5" viewBox="0 0 24 24" stroke="none" fill="none"> | ||
<g id="Interface / Settings"> | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,7 +11,11 @@ | |||||||||||||||||||||||||||||
let adminSection: Writable<string> = getContext("adminSection") | ||||||||||||||||||||||||||||||
adminSection.set("billing") | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
export let data | ||||||||||||||||||||||||||||||
interface Props { | ||||||||||||||||||||||||||||||
data: any; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
let { data }: Props = $props(); | ||||||||||||||||||||||||||||||
Comment on lines
+14
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance type safety by properly typing the data prop. While the migration to Svelte 5's Consider replacing the current interface with a more specific type definition: interface Props {
- data: any;
+ data: {
+ currentPlanId?: string;
+ isActiveCustomer: boolean;
+ hasEverHadSubscription: boolean;
+ };
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
let currentPlanId = data.currentPlanId ?? defaultPlanId | ||||||||||||||||||||||||||||||
let currentPlanName = pricingPlans.find( | ||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,11 @@ | |
let adminSection: Writable<string> = getContext("adminSection") | ||
adminSection.set("settings") | ||
|
||
export let data | ||
interface Props { | ||
data: any; | ||
} | ||
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider enhancing type safety by properly typing the data prop. The +interface Profile {
+ full_name?: string;
+ company_name?: string;
+ website?: string;
+ unsubscribed?: boolean;
+}
+
+interface User {
+ email?: string;
+}
+
interface Props {
- data: any;
+ data: {
+ profile: Profile;
+ user: User;
+ };
}
|
||
|
||
let { data }: Props = $props(); | ||
let { profile, user } = data | ||
</script> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,11 @@ | |
let adminSection: Writable<string> = getContext("adminSection") | ||
adminSection.set("settings") | ||
|
||
export let data | ||
interface Props { | ||
data: any; | ||
} | ||
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance type safety by properly typing the data prop. The interface Props {
- data: any;
+ data: {
+ user: {
+ email: string;
+ // Add other user properties as needed
+ };
+ };
}
|
||
|
||
let { data }: Props = $props(); | ||
|
||
let { user } = data | ||
</script> | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,10 @@ | ||||||||||||||||||||||||
<script lang="ts"> | ||||||||||||||||||||||||
import SettingsModule from "../settings_module.svelte" | ||||||||||||||||||||||||
export let data | ||||||||||||||||||||||||
interface Props { | ||||||||||||||||||||||||
data: any; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
Comment on lines
+3
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Strengthen type safety by properly typing the Props interface. Instead of using interface Props {
- data: any;
+ data: {
+ profile: {
+ unsubscribed?: boolean;
+ [key: string]: unknown;
+ };
+ };
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
let { data }: Props = $props(); | ||||||||||||||||||||||||
let { profile } = data | ||||||||||||||||||||||||
let unsubscribed = profile?.unsubscribed | ||||||||||||||||||||||||
Comment on lines
+7
to
9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider improving null safety and destructuring. While the migration to Svelte 5's - let { data }: Props = $props();
- let { profile } = data
- let unsubscribed = profile?.unsubscribed
+ let { data: { profile } }: Props = $props();
+ let unsubscribed = profile?.unsubscribed ?? false This change:
📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
</script> | ||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,7 +7,11 @@ | |||||
let adminSection: Writable<string> = getContext("adminSection") | ||||||
adminSection.set("settings") | ||||||
|
||||||
export let data | ||||||
interface Props { | ||||||
data: any; | ||||||
} | ||||||
|
||||||
let { data }: Props = $props(); | ||||||
Comment on lines
+10
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider strengthening type definitions. The interface Props {
- data: any;
+ data: {
+ user: {
+ email?: string;
+ amr?: Array<{ method: string }>;
+ };
+ supabase: SupabaseClient;
+ };
}
|
||||||
let { user, supabase } = data | ||||||
|
||||||
// True if definitely has a password, but can be false if they | ||||||
|
@@ -21,8 +25,8 @@ | |||||
// @ts-expect-error: we ignore because Supabase does not maintain an AMR typedef | ||||||
let usingOAuth = user?.amr?.find((x) => x.method === "oauth") ? true : false | ||||||
|
||||||
let sendBtn: HTMLButtonElement | ||||||
let sentEmail = false | ||||||
let sendBtn: HTMLButtonElement = $state() | ||||||
let sentEmail = $state(false) | ||||||
let sendForgotPassword = () => { | ||||||
sendBtn.disabled = true | ||||||
sendBtn.textContent = "Sending..." | ||||||
|
@@ -95,7 +99,7 @@ | |||||
<button | ||||||
class="btn btn-outline btn-wide {sentEmail ? 'hidden' : ''}" | ||||||
bind:this={sendBtn} | ||||||
on:click={sendForgotPassword} | ||||||
onclick={sendForgotPassword} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert to Svelte's event binding syntax. The change from - onclick={sendForgotPassword}
+ on:click={sendForgotPassword} 📝 Committable suggestion
Suggested change
|
||||||
>Send Set Password Email | ||||||
</button> | ||||||
<div class="success alert alert-success {sentEmail ? '' : 'hidden'}"> | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,7 +6,11 @@ | |||||||||||||||||||||||||
let adminSection: Writable<string> = getContext("adminSection") | ||||||||||||||||||||||||||
adminSection.set("settings") | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export let data | ||||||||||||||||||||||||||
interface Props { | ||||||||||||||||||||||||||
data: any; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance type safety by defining a more specific Props interface. The interface Props {
- data: any;
+ data: {
+ session: {
+ user: {
+ email: string;
+ } | null;
+ } | null;
+ };
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
let { data }: Props = $props(); | ||||||||||||||||||||||||||
let { session } = data | ||||||||||||||||||||||||||
</script> | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,7 +6,11 @@ | |||||||||||||||||||||||||
let adminSection: Writable<string> = getContext("adminSection") | ||||||||||||||||||||||||||
adminSection.set("settings") | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export let data | ||||||||||||||||||||||||||
interface Props { | ||||||||||||||||||||||||||
data: any; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance type safety by properly typing the data structure. Instead of using interface Props {
- data: any;
+ data: {
+ profile?: {
+ full_name?: string;
+ company_name?: string;
+ website?: string;
+ };
+ };
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
let { data }: Props = $props(); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
let { profile } = data | ||||||||||||||||||||||||||
</script> | ||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
<script lang="ts"> | ||
import { run } from 'svelte/legacy'; | ||
|
||
import { invalidate } from "$app/navigation" | ||
import { onMount } from "svelte" | ||
|
||
export let data | ||
interface Props { | ||
data: any; | ||
children?: import('svelte').Snippet; | ||
} | ||
Comment on lines
+7
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider strengthening type safety for the data prop. Using interface Props {
- data: any;
+ data: {
+ supabase: SupabaseClient;
+ session: Session | null;
+ };
children?: import('svelte').Snippet;
}
|
||
|
||
let { data, children }: Props = $props(); | ||
|
||
let { supabase, session } = data | ||
$: ({ supabase, session } = data) | ||
let { supabase, session } = $state(data) | ||
run(() => { | ||
({ supabase, session } = data) | ||
}); | ||
|
||
onMount(() => { | ||
const { data } = supabase.auth.onAuthStateChange((event, _session) => { | ||
|
@@ -18,4 +27,4 @@ | |
}) | ||
</script> | ||
|
||
<slot /> | ||
{@render children?.()} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,16 @@ | |
import type { SubmitFunction } from "@sveltejs/kit" | ||
import "../../../../app.css" | ||
|
||
export let data | ||
export let form: FormAccountUpdateResult | ||
interface Props { | ||
data: any; | ||
form: FormAccountUpdateResult; | ||
} | ||
Comment on lines
+6
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider improving type safety for the Props interface. The interface Props {
- data: any;
+ data: {
+ user: { email: string };
+ profile?: {
+ full_name?: string;
+ company_name?: string;
+ website?: string;
+ };
+ };
form: FormAccountUpdateResult;
}
|
||
|
||
let { data, form }: Props = $props(); | ||
|
||
let { user, profile } = data | ||
|
||
let loading = false | ||
let loading = $state(false) | ||
let fullName: string = profile?.full_name ?? "" | ||
let companyName: string = profile?.company_name ?? "" | ||
let website: string = profile?.website ?? "" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,14 @@ | |
import { goto } from "$app/navigation" | ||
import { onMount } from "svelte" | ||
|
||
export let data | ||
interface Props { | ||
data: any; | ||
} | ||
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve type safety by properly typing the Props interface. The interface Props {
- data: any;
+ data: {
+ supabase: SupabaseClient;
+ };
}
|
||
|
||
let { data }: Props = $props(); | ||
|
||
let { supabase } = data | ||
let message = "Signing out...." | ||
let message = $state("Signing out....") | ||
|
||
// on mount, sign out | ||
onMount(() => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<script> | ||
import { WebsiteName } from "./../../config" | ||
import "../../app.css" | ||
/** @type {{children?: import('svelte').Snippet}} */ | ||
let { children } = $props(); | ||
</script> | ||
|
||
<div class="navbar bg-base-100 container mx-auto"> | ||
|
@@ -34,8 +36,8 @@ | |
</li> | ||
</ul> | ||
<div class="dropdown dropdown-end sm:hidden"> | ||
<!-- svelte-ignore a11y-label-has-associated-control --> | ||
<!-- svelte-ignore a11y-no-noninteractive-tabindex --> | ||
<!-- svelte-ignore a11y_label_has_associated_control --> | ||
<!-- svelte-ignore a11y_no_noninteractive_tabindex --> | ||
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider addressing accessibility issues instead of ignoring them While the comment format update is correct, consider addressing these accessibility concerns:
Here's a potential improvement: - <!-- svelte-ignore a11y_label_has_associated_control -->
- <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
- <label tabindex="0" class="btn btn-ghost btn-circle">
+ <button
+ aria-label="Menu"
+ aria-expanded="false"
+ aria-controls="mobile-menu"
+ class="btn btn-ghost btn-circle"> Also applies to: 56-56 |
||
<label tabindex="0" class="btn btn-ghost btn-circle"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
|
@@ -51,7 +53,7 @@ | |
/></svg | ||
> | ||
</label> | ||
<!-- svelte-ignore a11y-no-noninteractive-tabindex --> | ||
<!-- svelte-ignore a11y_no_noninteractive_tabindex --> | ||
<ul | ||
tabindex="0" | ||
class="menu menu-lg dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52 font-bold" | ||
|
@@ -72,7 +74,7 @@ | |
</div> | ||
|
||
<div class=""> | ||
<slot /> | ||
{@render children?.()} | ||
</div> | ||
|
||
<!-- Spacer grows so the footer can be at bottom on short pages --> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Based on the codebase analysis, there are multiple areas that need attention for the Svelte 5 migration:
$:
reactive declarations that should be migrated to$derived
$state()
are already being used, showing partial migration to Svelte 5 runesonMount
) are used in multiple components that need review:writable
) in src/routes/(admin)/account/(menu)/+layout.svelte needs to be migrated to$state
bind:
directives that need compatibility verification🔗 Analysis chain
The upgrade to Svelte 5 (
^5.0.0
) represents a significant change as it's currently in beta. This version introduces major changes like the runes syntax and a new reactivity model.Run this check to identify potential breaking changes:
Let me gather more information about the Svelte 5 migration readiness by checking for other potential breaking changes.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 1439
Script:
Length of output: 17828