Skip to content

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

Closed
@asimen1

Description

@asimen1

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions