#How can I get the window object in an .mdx file?

5 messages · Page 1 of 1 (latest)

gusty shale
#

✅  Test.svelte persists a Svelte store to local storage using the window object.

✅  I can import & use Test.svelte in an .astro file with the client:only directive as per the docs.

✅  When I run the same code in an .mdx file I get "window is not defined".

(Svelte components that don't depend on window run as expected in an .mdx file.)

Is there a way to access the window object with a .mdx file?

StackBlitz: https://stackblitz.com/edit/astro-jtddy8

Astro project with a Svelte component that accesses local storage through a Svelte store.
Works in .astro file but not in .mdx file.

thorn bronze
#

You need to specify the framework being used for your client:only directive, so in this case client:only="svelte".

I think this should fix your issue but I am not able to modify the Stackblitz repro and check on mobile.

shell dawn