closure-compiler: Generates invalid output with certain properties

The React team encountered an issue with Closure Compiler when compiling the React DOM bundle. It’s quite specific, but it seems to somehow confuse the compiler into re-using a variable that is not safe to use given a given scenario.

https://github.com/facebook/react/pull/18670#issuecomment-623481140

Reproduction steps:

This error should be seen:

TypeError: Cannot read property 'focusedElem' of null. It seems to be related to JSCompiler_inline_result. Which incorrectly gets re-used from a null value.

Specifically, the change that causes this is when we convert this logic:

function prepareForCommit(containerInfo) {
  ...
}
...
prepareForCommit(root.containerInfo);

to:

function prepareForCommit(containerInfo) {
  ...
  return null;
}
...
prepareForCommit(root.containerInfo) || null;

These are the flags we use for this particular build:

compilation_level: 'SIMPLE'
language_in: 'ECMASCRIPT_2015'
language_out: 'ECMASCRIPT5_STRICT'
env: 'CUSTOM'
warning_level: 'QUIET'
apply_input_source_maps: false
use_types_for_optimization: false
process_common_js_modules: false
rewrite_polyfills: false
inject_libraries: false
assume_function_wrapper: true

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 29 (26 by maintainers)

Most upvoted comments

Ok, great, thanks for catching that!

Then the actual repro steps are:

git clone https://github.com/trueadm/react.git
cd react/
git checkout break-gcc
yarn install --ignore-engines
yarn build --type=NODE_PROD
yarn test-prod-build ReactDOMServerIntegrationTextarea

And that does give the expected error, namely (several) failed tests with:

 TypeError: Cannot read property 'focusedElem' of null