-
Notifications
You must be signed in to change notification settings - Fork 69
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
Fix Inertia SSR errors #53
base: main
Are you sure you want to change the base?
Conversation
Using SSR will also cause a flash of light theme for users who have previously selected a dark theme because the theme is saved in localstorage. I would love to see persisting theme in session or some other way, so we can inject the theme class in app blade during SSR and not have to wait for javascript to change it. |
Yeah, cookies can also work and I've gotten by using that route as well. Not sure if it necessarily falls on the responsibility of the starter kit though, as it's fairly easy to setup in user land if that's desired in the scaffolded app. |
For those stumbling upon this wondering about the dark mode flash, I have a branch demoing how to prevent it using this starter kit based on the changes from this PR. TL;DR, use a cookie to keep the dark mode state. |
// For SSR, we can't access the window location, so can only render the layout on the client | ||
if (typeof window === 'undefined') { | ||
return null; | ||
} |
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.
There is url in usePage hooks, why not just use that?
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.
We certainly could, both will accomplish the same thing I'm pretty sure. This is just a preference of being explicit about rendering on the server.
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.
I guess in that context I prefer that way too, thanks for the answer.
90fcf59
to
011ee04
Compare
There were a handful of errors when running SSR with Inertia, primarily around accessing the
window
and missing some middleware that's required for SSR contexts. This PR resolves those issues. I haven't checked the Vue starter kit yet, though Is suspect that same thing is probably happening there as well.