diff --git a/packages/react-dom/src/client/ReactDOMRoot.js b/packages/react-dom/src/client/ReactDOMRoot.js index 1c673bf2543a0..4c0355a2a0ca3 100644 --- a/packages/react-dom/src/client/ReactDOMRoot.js +++ b/packages/react-dom/src/client/ReactDOMRoot.js @@ -106,17 +106,19 @@ ReactDOMHydrationRoot.prototype.render = ReactDOMRoot.prototype.render = } if (__DEV__) { - if (typeof arguments[1] === 'function') { + // @nocollapse - avoid GCC optimizations affecting function arity + const args = arguments; + if (typeof args[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 (isValidContainer(args[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 (typeof args[1] !== 'undefined') { console.error( 'You passed a second argument to root.render(...) but it only accepts ' + 'one argument.', @@ -131,7 +133,9 @@ ReactDOMHydrationRoot.prototype.unmount = ReactDOMRoot.prototype.unmount = // $FlowFixMe[missing-this-annot] function (): void { if (__DEV__) { - if (typeof arguments[0] === 'function') { + // @nocollapse - avoid GCC optimizations affecting function arity + const args = arguments; + if (typeof args[0] === 'function') { console.error( 'does not support a callback argument. ' + 'To execute a side effect after rendering, declare it in a component body with useEffect().', diff --git a/packages/react-reconciler/src/ReactFiberHooks.js b/packages/react-reconciler/src/ReactFiberHooks.js index 8affe4804b8ab..be2e280ba6e0f 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.js +++ b/packages/react-reconciler/src/ReactFiberHooks.js @@ -3644,7 +3644,9 @@ function dispatchReducerAction( action: A, ): void { if (__DEV__) { - if (typeof arguments[3] === 'function') { + // @nocollapse - avoid GCC optimizations affecting function arity + const args = arguments; + if (typeof args[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 ' + @@ -3684,7 +3686,9 @@ function dispatchSetState( action: A, ): void { if (__DEV__) { - if (typeof arguments[3] === 'function') { + // @nocollapse - avoid GCC optimizations affecting function arity + const args = arguments; + if (typeof args[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 ' +