Skip to content

Commit

Permalink
Merge pull request #3415 from torgeirsk/fix-webpack-nonce-cra
Browse files Browse the repository at this point in the history
use window.__webpack_nonce__ to avoid overwriting by react-scripts
  • Loading branch information
quantizor committed Mar 10, 2021
2 parents c14b039 + 15b0796 commit 6151662
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/styled-components/src/utils/nonce.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @flow
/* eslint-disable camelcase, no-undef */

declare var __webpack_nonce__: string;
declare var window: { __webpack_nonce__: string };

const getNonce = () => {
return typeof __webpack_nonce__ !== 'undefined' ? __webpack_nonce__ : null;
return typeof window.__webpack_nonce__ !== 'undefined' ? window.__webpack_nonce__ : null;
};

export default getNonce;
3 changes: 3 additions & 0 deletions scripts/jest/config.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ module.exports = Object.assign({}, baseConfig, {
setupFiles: ['raf/polyfill', '<rootDir>/src/test/globals.js'],
setupFilesAfterEnv: ['<rootDir>/test-utils/setupTestFramework.js'],
testPathIgnorePatterns: ['<rootDir>/src/native', '<rootDir>/src/primitives'],
globals: {
window: { __webpack_nonce__: 'test' },
},
});

0 comments on commit 6151662

Please sign in to comment.