Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

JoeyMckenzie
Copy link
Contributor

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.

@Linux123123
Copy link

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.

@JoeyMckenzie
Copy link
Contributor Author

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.

@JoeyMckenzie
Copy link
Contributor Author

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;
}

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?

Copy link
Contributor Author

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.

Copy link

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.

@JoeyMckenzie JoeyMckenzie force-pushed the fix/inertia-ssr-errors branch from 90fcf59 to 011ee04 Compare March 2, 2025 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants