Skip to content

Commit

Permalink
Use same message on client and server
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Sep 27, 2022
1 parent 73a0d14 commit d241c05
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5605,7 +5605,7 @@ describe('ReactDOMFizzServer', () => {
}
expect(logs).toEqual([]);
expect(caughtError.message).toContain(
'Cannot call a function returned by useEvent',
"A function wrapped in useEvent can't be called during rendering.",
);
expect(reportedServerErrors).toEqual([caughtError]);
});
Expand Down
4 changes: 3 additions & 1 deletion packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1877,7 +1877,9 @@ function mountEvent<T>(callback: () => T): () => T {

function event() {
if (isInvalidExecutionContextForEventFunction()) {
throw new Error('An event from useEvent was called during render.');
throw new Error(
"A function wrapped in useEvent can't be called during rendering.",
);
}
return ref.current.apply(undefined, arguments);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/react-reconciler/src/ReactFiberHooks.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -1877,7 +1877,9 @@ function mountEvent<T>(callback: () => T): () => T {

function event() {
if (isInvalidExecutionContextForEventFunction()) {
throw new Error('An event from useEvent was called during render.');
throw new Error(
"A function wrapped in useEvent can't be called during rendering.",
);
}
return ref.current.apply(undefined, arguments);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/__tests__/useEvent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('useEvent', () => {

ReactNoop.render(<Counter incrementBy={1} />);
expect(Scheduler).toFlushAndThrow(
'An event from useEvent was called during render',
"A function wrapped in useEvent can't be called during rendering.",
);

// If something throws, we try one more time synchronously in case the error was
Expand Down
2 changes: 1 addition & 1 deletion packages/react-server/src/ReactFizzHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ export function useCallback<T>(

function throwOnUseEventCall() {
throw new Error(
'Cannot call a function returned by useEvent during server rendering.',
"A function wrapped in useEvent can't be called during rendering.",
);
}

Expand Down
7 changes: 3 additions & 4 deletions scripts/error-codes/codes.json
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@
"437": "the \"precedence\" prop for links to stylesheets expects to receive a string but received something of type \"%s\" instead.",
"438": "An unsupported type was passed to use(): %s",
"439": "We didn't expect to see a forward reference. This is a bug in the React Server.",
"440": "An event from useEvent was called during render.",
"441": "An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.",
"442": "Cannot call a function returned by useEvent during server rendering."
}
"440": "A function wrapped in useEvent can't be called during rendering.",
"441": "An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error."
}

0 comments on commit d241c05

Please sign in to comment.