wobsoriano / svelte-clerk

Community Clerk Svelte SDK.
Other
36 stars 4 forks source link

Cannot read properties of undefined (reading 'initialState') #99

Open torrfura opened 3 days ago

torrfura commented 3 days ago

We get this from time to time:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'initialState')
    in ClerkProvider.svelte
    in context.svelte 

    const ctx = useClerkContext();

Current solution is to clear all cookies and make a hard refresh. Not super-critical, but happends from time to time in development.

wobsoriano commented 3 days ago

Interesting. Meaning the $page.data here becomes undefined in some instance. Im thinking of just removing that part and letting devs actually set the state in ClerkProvider:

<script lang="ts">
    import type { Snippet } from '@svelte';
    import { ClerkProvider } from 'svelte-clerk';
    import { PUBLIC_CLERK_PUBLISHABLE_KEY } from '$env/static/public';

    const { children, data }: { children: Snippet } = $props();
</script>

<!-- ... -->

<ClerkProvider {...data} publishableKey={PUBLIC_CLERK_PUBLISHABLE_KEY}>
    {@render children()}
</ClerkProvider>