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

Avoid GCC optimizations affecting function arity #31598

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/react-dom/src/client/ReactDOMRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
eps1lon marked this conversation as resolved.
Show resolved Hide resolved
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.',
Expand Down
3 changes: 2 additions & 1 deletion packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3718,7 +3718,8 @@ function dispatchReducerAction<S, A>(
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 ' +
Expand Down
11 changes: 11 additions & 0 deletions scripts/rollup/validate/eslintrc.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions scripts/rollup/validate/eslintrc.cjs2015.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions scripts/rollup/validate/eslintrc.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions scripts/rollup/validate/eslintrc.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions scripts/rollup/validate/eslintrc.rn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading