Skip to content

Commit

Permalink
Remove "string" from invalid ref error message
Browse files Browse the repository at this point in the history
String is no longer a valid accepted type. (Except when
`disableStringRefs` is off, in the Meta build, but even in that case
they are deprecated so we shouldn't list it as a valid type.)
  • Loading branch information
acdlite committed Feb 29, 2024
1 parent fb87afe commit ea0180b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
8 changes: 2 additions & 6 deletions packages/react-dom/src/__tests__/refs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,7 @@ describe('ref swapping', () => {
await act(() => {
root.render(<div ref={Symbol('foo')} />);
});
}).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
Expand All @@ -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');
});
});

Expand Down
3 changes: 1 addition & 2 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -1035,9 +1035,8 @@ function markRef(current: Fiber | null, workInProgress: Fiber) {
}
} else {
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) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/error-codes/codes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ea0180b

Please sign in to comment.