-
Notifications
You must be signed in to change notification settings - Fork 403
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(storage-plugin): fix undefined localStorage error during SSR (#1118) #1119
Conversation
This fixes the mentioned issue, I am just not sure if this is a solution you guys are happy with. Please give me a short review if you have other ideas of fixing the issue. |
Regarding tests I'd also welcome your input, adding the storage module to app.server.module.ts or moving it from app.browser.module.ts to app.module.ts should be enough? I unfortunately cannot run the SSR tests locally, so it's hard for me to just try it out. |
@Dav1dde I believe you and can't check right now, but the |
So we would return null in if (isPlatformServer(platformId)) {
return null: // new InMemoryStorageEngine();
} And additionally skip the plugin when platform = server? Out of curiosity, I was under the impression that angular universal has to bootstrap the application for every request, simply because stuff like the URL changes and maybe app initializer or other services may inject the request or response. In which case this wouldn't be problematic. |
@Dav1dde You're right but this in memory engine seems meaningless, I don't see a purpose of it. The user reloads page - the new in memory engine is created right? Or I'm missing something. |
You're right it's basically useless if the user does not inject PS: I'll leave all the commits in for now, I will rebase them into one once you're satisified with the PR. |
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.
LGTM
Just need an approve from one more member
Awesome, thanks for your help. Let me know if you want the commits squashed. |
@Dav1dde We squash, no worries :D |
@Dav1dde I will happy if you add plugin NgxsStoragePluginModule.forRoot({ key: [TODOS_STORAGE_KEY] }) to app.server.module.ts https://github.com/ngxs/store/blob/master/integration/app/app.server.module.ts If the tests pass, then the SSR works with storage-plugin! |
@splincode done and tests seem to pass. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #1118
What is the new behavior?
Storage during SSR is emulated with an empty in memory storage engine, which can still be modified by the user by providing a different storage engine.
Does this PR introduce a breaking change?