-
Notifications
You must be signed in to change notification settings - Fork 20
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
[Bug] Cannot read properties of undefined setItem
when set theme from NgDocThemeService in SSR
#126
Comments
Hey thanks for the ticket and link to the repo I'll try to check it today |
Okay, I looked at the repository. The first thing I didn't quite understand is why you manually call constructor(protected readonly themeService: NgDocThemeService) {
afterRender(() => this.themeService.set('custom-theme'));
} I encountered this issue in the application initialization function when NgDoc tries to determine which theme to load for the application based on the value in However, I want to explore this issue in the future and fix it because during a quick page refresh, you may notice that the application briefly had the default theme and then switched to the one set in You can also completely abandon the theme looks sick btw. :) |
Hi @skoropadas, thank you for your help.
The reason that I set the theme manually is to fix the glitch while the theme is shifting on page refresh. For now, I will override the theme by CSS or simply However, I'm looking forward to set the theme with config in SSR or pre-render. Thank you so much, for your help. FYI. As far, as I've tried many libraries in Angular. I think |
Thank you! :) Yes, the glitch occurs because Angular pre-renders the page with the default theme. After that, on the client side, scripts are loaded that perform hydration, fetch the theme set in localStorage, and change it. At the moment, it seems to me that it's not entirely possible to fix this in the current implementation because the delay will still occur due to loading the theme via HTTP. Since the themes are lightweight due to the ability to configure everything with CSS variables, I think it makes sense to switch to CSS classes. Therefore, importing the theme in styles.css is a good solution. I will address this later since I wanted to slightly expand the theme functionality, adding the ability to set settings for the application, such as settings for the header or sidebar, to implement fullscreen themes, for example. |
Is this a regression?
Yes
Description
Overview
Hi, I'm using
ng-doc
to create my docs. I saw an error aboutsetItem
when set the theme withNgDocThemeService
in SSR pre-render.For now, my docs is working properly. But I'm curious about the error that appeared, I'm not sure whether I missed some configs or not.
Actually, I have been looking at the source code.
setItem
is fromlocalStorage
, used byNgDocThemeService
. It would appear an error on the server side from my usage.Expected Result
The error should not show when set the theme in SSR.
Or, my code should be updated to suitable config.
Screenshots
If you have any feedback or suggestions, please let me know.
Please provide the exception or error you saw
OS
Unix (Linux, macOS, etc.)
Browser
Chrome
Node version
v18.19.0
Anything else?
You can see my code from this repo:
https://github.com/runyasak/ng-storefront-ui/tree/docs/projects/docs
The text was updated successfully, but these errors were encountered: