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/nonce in ssr #3755

Merged
merged 2 commits into from Sep 27, 2022
Merged

Conversation

samimakicc
Copy link

Fixes #3571
Reverts #3415 and #3446

#3415 was a fix for issue #3414 but I believe the issue wasn't in styled-components but maybe just lack of documentation on how __webpack_nonce__ should be used. And #3446 was just a fix on top of #3415.

__webpack_nonce__ is a magic variable and webpack does some special handling for it. To my understanding it should be set at the beginning of entry point and used directly like __webpack_nonce__ = 'secret' instead of through window (which doesn't even exist on server).

@samimakicc
Copy link
Author

@torgeirsk could you check if your use case described in #3414 works with this fix (or with v5.2.1 where that issue was originally reported) if you set __webpack_nonce__ instead of window.__webpack_nonce__?

Create a file (for example create-nonce.js) with content

// eslint-disable-next-line no-undef
__webpack_nonce__ = 'secret';

And then import that file as first thing in your entry point (probably index.js):

import './create-nonce';

Copy link

@3imed-jaberi 3imed-jaberi left a comment

Choose a reason for hiding this comment

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

sgtm +1

@latema
Copy link

latema commented Sep 27, 2022

Any chance to get this reviewed and merged? For now I have patched this myself in my project with patch-package, but it would be nice to have this fix in styled-components v5.

@agriffis
Copy link
Contributor

@probablyup I don't use webpack personally, but this looks good at a glance, and seems to match more closely to what's in v6.

Copy link
Contributor

@quantizor quantizor left a comment

Choose a reason for hiding this comment

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

LGTM, I agree. I had it closer to this implementation originally and someone sent a PR with the current impl saying the other didn't work, but it's entirely possible that was also user error.

@quantizor quantizor merged commit 4bace25 into styled-components:legacy-v5 Sep 27, 2022
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

5 participants