#`localStorage` in SPA mode

1 messages · Page 1 of 1 (latest)

solemn sequoia
#

I'm currently running Remix in SPA mode, and I'm running into an issue that during both build (npx remix vite:build) and dev (npx remix vite:dev) modes, I get that localStorage is not defined.

This stems from the fact that I originally wrote an AuthProvider module (for lack of a better word) since I'm migrating to Remix from a React Router codebase (hence, also, SPA mode). This AuthProvider uses local storage to store a boolean of whether you're logged in (i.e., whether the cookie from my backend is probably valid or not).

I know that this is likely due to Remix/Vite hydrating the generated index.html file, but I'm not sure how it's running into that when my AuthProvider is only called from client-side functions (i.e., a clientLoader, clientAction, or useEffect hook).

What's the best way to "fix" this?

solemn sequoia
#

Nevermind, figured out that I needed to name the AuthProvider file to AuthProvider.client.ts to force it to be client-only