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 errors when accessing document global on server #308

Closed

Conversation

unverbraucht
Copy link

When using the plugin in a server-side rendering context there is no document global where script or link tags could be added to. In this case typically all scripts and link tags are collected and added by the renderer itself so nothing needs to be executed by the plugin on require.

This patch detects the existence of the document global and skips adding nodes if it doesn't exist. Also fixed test cases. Feedback welcome, maybe there is a better way to do this?

@unverbraucht
Copy link
Author

This should also fix #296

@@ -330,6 +330,7 @@ class ExtractCssChunksPlugin {
'',
`// ${pluginName} CSS loading`,
`var supportsPreload = ${supportsPreload}`,
`if (typeof document === "undefined") { return; }`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could even happen at the very beginning to prevent the supportsPreload function execution

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.

None yet

3 participants