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

Bug: 'use strict' at global level causes issues with scripts concatenation. #19591

Closed
asimen1 opened this issue Aug 12, 2020 · 1 comment · Fixed by #19614
Closed

Bug: 'use strict' at global level causes issues with scripts concatenation. #19591

asimen1 opened this issue Aug 12, 2020 · 1 comment · Fixed by #19614

Comments

@asimen1
Copy link

asimen1 commented Aug 12, 2020

React version: 16.13.1

Even though React's code (and other packages like ReactDOM) are wrapped in a IIFE, the code applies an entire script strict mode by placing a 'use strict' before any other statement:
https://cdnjs.cloudflare.com/ajax/libs/react/16.13.1/umd/react.production.min.js
https://cdnjs.cloudflare.com/ajax/libs/react/16.13.1/umd/react.development.js
https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.13.1/umd/react-dom.production.min.js
https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.13.1/umd/react-dom.development.min.js

MDN mentions the "trap" of concatenating conflicting scripts strict mode when using the entire script strict mode, see here.

Steps To Reproduce

  1. Create a file with React's code at the top and concat an expression that causes a 'use strict' violation
  2. Load this file as a script tag

Link to code example: https://stackblitz.com/edit/use-strict-react?file=index.js
(Scroll to bottom of file to see the concatenated expressions)

The current behavior

'use strict' mode is enforced on all the concatenated code, even if it was not defined as 'strict'.
As a result, 'strict' violations at the other concatenated libraries will now throw errors (instead of silencing them), causing the script to stop execution.

The expected behavior

Global 'use strict' should not be used and should be replaced with function scope strict mode (which already exist in some cases of React IIFE bundles code wrappers, like react-dom.development).

Misc info

@asimen1 asimen1 added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Aug 12, 2020
@bvaughn bvaughn added Type: Bug Type: Discussion and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Aug 12, 2020
@asimen1
Copy link
Author

asimen1 commented Aug 17, 2020

@bvaughn @koba04 @gaearon Thanks for the super quick handling!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants