-
-
Notifications
You must be signed in to change notification settings - Fork 48
no-top-level-browser-globals
rule
#1203
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
Labels
Comments
no-browser-globals
ruleno-browser-globals-at-top-level
rule
Great idea, how about |
no-browser-globals-at-top-level
ruleno-top-level-browser-globals
rule
Question: would |
Hi @benmccann. if (import.meta.env.SSR) {
// ... server only logic
} else {
localStorage.getItem('myCat');
} |
I think the node-specific global variables are:
I think it's not a problem since they are rarely used or the bundler injects them. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Motivation
You can add a browser global to a
.svelte
file that will cause it to error during SSR and often nothing will catch it right now. Sometimes the.svelte
file never gets loaded on the server during development making this easy to miss until it is shipped to production. I.e. if you navigate to the page via client-side routing you won't see the error. You have to refresh the page to see itDescription
browser globals should not be allowed directly inside a script block. There are a lot of other cases you can use them that are valid and so we can't catch all invalid cases, but hopefully we could catch the most obviously wrong ones
Examples
Additional comments
Users may want to disable this rule if building a SPA. I think it's generally good practice even if you're building a SPA to leave this rule enabled in case you later want to enable SSR, but many users would feel that to be unnecessary overhead
The text was updated successfully, but these errors were encountered: