diff --git a/packages/react-dom/src/__tests__/refs-test.js b/packages/react-dom/src/__tests__/refs-test.js index f12dc7e52b8aa..a749e63b55bea 100644 --- a/packages/react-dom/src/__tests__/refs-test.js +++ b/packages/react-dom/src/__tests__/refs-test.js @@ -414,9 +414,7 @@ describe('ref swapping', () => { await act(() => { root.render(
); }); - }).rejects.toThrow( - 'Expected ref to be a function, a string, an object returned by React.createRef(), or null.', - ); + }).rejects.toThrow('Expected ref to be a function'); }); // @gate !enableRefAsProp @@ -434,9 +432,7 @@ describe('ref swapping', () => { key: null, }); }); - }).rejects.toThrow( - 'Expected ref to be a function, a string, an object returned by React.createRef(), or null.', - ); + }).rejects.toThrow('Expected ref to be a function'); }); }); diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.js b/packages/react-reconciler/src/ReactFiberBeginWork.js index e87df807a486f..0bfc2fbef18cc 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.js @@ -1037,7 +1037,7 @@ function markRef(current: Fiber | null, workInProgress: Fiber) { if (typeof ref !== 'function' && typeof ref !== 'object') { // TODO: Remove "string" from error message. throw new Error( - 'Expected ref to be a function, a string, an object returned by React.createRef(), or null.', + 'Expected ref to be a function, an object returned by React.createRef(), or undefined/null.', ); } if (current === null || current.ref !== ref) { diff --git a/scripts/error-codes/codes.json b/scripts/error-codes/codes.json index 1471b340098a0..2a14f02dd03be 100644 --- a/scripts/error-codes/codes.json +++ b/scripts/error-codes/codes.json @@ -280,7 +280,7 @@ "281": "Finished root should have a work-in-progress. This error is likely caused by a bug in React. Please file an issue.", "282": "If the root does not have an updateQueue, we should have already bailed out. This error is likely caused by a bug in React. Please file an issue.", "283": "Element type is invalid. Received a promise that resolves to: %s. Promise elements must resolve to a class or function.", - "284": "Expected ref to be a function, a string, an object returned by React.createRef(), or null.", + "284": "Expected ref to be a function, an object returned by React.createRef(), or undefined/null.", "285": "The root failed to unmount after an error. This is likely a bug in React. Please file an issue.", "286": "%s(...): the first argument must be a React class instance. Instead received: %s.", "287": "It is not supported to run the profiling version of a renderer (for example, `react-dom/profiling`) without also replacing the `schedule/tracking` module with `schedule/tracking-profiling`. Your bundler might have a setting for aliasing both modules. Learn more at https://reactjs.org/link/profiling",