diff --git a/packages/react-dom/src/client/ReactDOMRoot.js b/packages/react-dom/src/client/ReactDOMRoot.js index 98ec6f9236fed..091591667603e 100644 --- a/packages/react-dom/src/client/ReactDOMRoot.js +++ b/packages/react-dom/src/client/ReactDOMRoot.js @@ -107,17 +107,18 @@ ReactDOMHydrationRoot.prototype.render = ReactDOMRoot.prototype.render = } if (__DEV__) { - if (typeof arguments[1] === 'function') { + // Avoid GCC optimizations affecting function arity + if (arguments.length >= 2 && typeof arguments[1] === 'function') { console.error( 'does not support the second callback argument. ' + 'To execute a side effect after rendering, declare it in a component body with useEffect().', ); - } else if (isValidContainer(arguments[1])) { + } else if (arguments.length >= 2 && isValidContainer(arguments[1])) { console.error( 'You passed a container to the second argument of root.render(...). ' + "You don't need to pass it again since you already passed it to create the root.", ); - } else if (typeof arguments[1] !== 'undefined') { + } else if (arguments.length >= 2 && typeof arguments[1] !== 'undefined') { console.error( 'You passed a second argument to root.render(...) but it only accepts ' + 'one argument.', diff --git a/packages/react-reconciler/src/ReactFiberHooks.js b/packages/react-reconciler/src/ReactFiberHooks.js index d7f9d00e79bcf..1d1e787f0b9a7 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.js +++ b/packages/react-reconciler/src/ReactFiberHooks.js @@ -3718,7 +3718,8 @@ function dispatchReducerAction( action: A, ): void { if (__DEV__) { - if (typeof arguments[3] === 'function') { + // Avoid GCC optimizations affecting function arity + if (arguments.length >= 4 && typeof arguments[3] === 'function') { console.error( "State updates from the useState() and useReducer() Hooks don't support the " + 'second callback argument. To execute a side effect after ' + diff --git a/scripts/rollup/validate/eslintrc.cjs.js b/scripts/rollup/validate/eslintrc.cjs.js index fa4b9cb979cf5..4594dfe3650d2 100644 --- a/scripts/rollup/validate/eslintrc.cjs.js +++ b/scripts/rollup/validate/eslintrc.cjs.js @@ -83,6 +83,17 @@ module.exports = { rules: { 'no-undef': 'error', 'no-shadow-restricted-names': 'error', + 'no-restricted-syntax': [ + 'error', + // TODO: Can be removed once we upgrade GCC to a version without `optimizeArgumentsArray` optimization. + { + selector: 'Identifier[name=/^JSCompiler_OptimizeArgumentsArray_/]', + message: + 'Google Closure Compiler optimized `arguments` access. ' + + 'This affects function arity. ' + + 'Access `arguments.length` to avoid this optimization', + }, + ], }, // These plugins aren't used, but eslint complains if an eslint-ignore comment diff --git a/scripts/rollup/validate/eslintrc.cjs2015.js b/scripts/rollup/validate/eslintrc.cjs2015.js index 64d83ff90c241..1a769f079354a 100644 --- a/scripts/rollup/validate/eslintrc.cjs2015.js +++ b/scripts/rollup/validate/eslintrc.cjs2015.js @@ -78,6 +78,17 @@ module.exports = { rules: { 'no-undef': 'error', 'no-shadow-restricted-names': 'error', + 'no-restricted-syntax': [ + 'error', + // TODO: Can be removed once we upgrade GCC to a version without `optimizeArgumentsArray` optimization. + { + selector: 'Identifier[name=/^JSCompiler_OptimizeArgumentsArray_/]', + message: + 'Google Closure Compiler optimized `arguments` access. ' + + 'This affects function arity. ' + + 'Access `arguments.length` to avoid this optimization', + }, + ], }, // These plugins aren't used, but eslint complains if an eslint-ignore comment diff --git a/scripts/rollup/validate/eslintrc.esm.js b/scripts/rollup/validate/eslintrc.esm.js index 80572e85cd8c3..3d0e2fa79b58c 100644 --- a/scripts/rollup/validate/eslintrc.esm.js +++ b/scripts/rollup/validate/eslintrc.esm.js @@ -80,6 +80,17 @@ module.exports = { rules: { 'no-undef': 'error', 'no-shadow-restricted-names': 'error', + 'no-restricted-syntax': [ + 'error', + // TODO: Can be removed once we upgrade GCC to a version without `optimizeArgumentsArray` optimization. + { + selector: 'Identifier[name=/^JSCompiler_OptimizeArgumentsArray_/]', + message: + 'Google Closure Compiler optimized `arguments` access. ' + + 'This affects function arity. ' + + 'Access `arguments.length` to avoid this optimization', + }, + ], }, // These plugins aren't used, but eslint complains if an eslint-ignore comment diff --git a/scripts/rollup/validate/eslintrc.fb.js b/scripts/rollup/validate/eslintrc.fb.js index 9f344c5aac3aa..f678723460080 100644 --- a/scripts/rollup/validate/eslintrc.fb.js +++ b/scripts/rollup/validate/eslintrc.fb.js @@ -71,6 +71,17 @@ module.exports = { rules: { 'no-undef': 'error', 'no-shadow-restricted-names': 'error', + 'no-restricted-syntax': [ + 'error', + // TODO: Can be removed once we upgrade GCC to a version without `optimizeArgumentsArray` optimization. + { + selector: 'Identifier[name=/^JSCompiler_OptimizeArgumentsArray_/]', + message: + 'Google Closure Compiler optimized `arguments` access. ' + + 'This affects function arity. ' + + 'Access `arguments.length` to avoid this optimization', + }, + ], }, // These plugins aren't used, but eslint complains if an eslint-ignore comment diff --git a/scripts/rollup/validate/eslintrc.rn.js b/scripts/rollup/validate/eslintrc.rn.js index d18516f802304..db6f12f75e9b7 100644 --- a/scripts/rollup/validate/eslintrc.rn.js +++ b/scripts/rollup/validate/eslintrc.rn.js @@ -73,6 +73,17 @@ module.exports = { rules: { 'no-undef': 'error', 'no-shadow-restricted-names': 'error', + 'no-restricted-syntax': [ + 'error', + // TODO: Can be removed once we upgrade GCC to a version without `optimizeArgumentsArray` optimization. + { + selector: 'Identifier[name=/^JSCompiler_OptimizeArgumentsArray_/]', + message: + 'Google Closure Compiler optimized `arguments` access. ' + + 'This affects function arity. ' + + 'Access `arguments.length` to avoid this optimization', + }, + ], }, // These plugins aren't used, but eslint complains if an eslint-ignore comment