-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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: only run DOM operations in the client when there is a document (#17570) #18202
base: main
Are you sure you want to change the base?
Conversation
Only run DOM operations in the client when there is a document (vitejs#17570)
Run & review this pull request in StackBlitz Codeflow. |
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 think we need a warning that tells importing CSS inside worker does not work.
if (!hasDocument) { | ||
return | ||
} | ||
|
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 think the only change needed is this line?
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.
Why would we only change this line? There are many DOM operations that will fail in workers, so it seemed best to make each one of them safe. Even if some may be safe today (e.g., first hasDocument
check prevents others from running), if the code paths change at all they will throw errors as well.
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.
Hmm, that's true. I actually forgot about this line.
vite/packages/vite/src/node/plugins/css.ts
Line 522 in a577828
`import { updateStyle as __vite__updateStyle, removeStyle as __vite__removeStyle } from ${JSON.stringify( |
While I think adding
hasDocument
check everywhere feels error prone as well, I think it's fine for now.
I ran prettier and created another commit but the linter still fails. Not sure what to do. |
Probably you need to run |
Description
Fixes #17570