Skip to content

Commit d241c05

Browse files
committed
Use same message on client and server
1 parent 73a0d14 commit d241c05

File tree

6 files changed

+12
-9
lines changed

6 files changed

+12
-9
lines changed

packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5605,7 +5605,7 @@ describe('ReactDOMFizzServer', () => {
56055605
}
56065606
expect(logs).toEqual([]);
56075607
expect(caughtError.message).toContain(
5608-
'Cannot call a function returned by useEvent',
5608+
"A function wrapped in useEvent can't be called during rendering.",
56095609
);
56105610
expect(reportedServerErrors).toEqual([caughtError]);
56115611
});

packages/react-reconciler/src/ReactFiberHooks.new.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1877,7 +1877,9 @@ function mountEvent<T>(callback: () => T): () => T {
18771877

18781878
function event() {
18791879
if (isInvalidExecutionContextForEventFunction()) {
1880-
throw new Error('An event from useEvent was called during render.');
1880+
throw new Error(
1881+
"A function wrapped in useEvent can't be called during rendering.",
1882+
);
18811883
}
18821884
return ref.current.apply(undefined, arguments);
18831885
}

packages/react-reconciler/src/ReactFiberHooks.old.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1877,7 +1877,9 @@ function mountEvent<T>(callback: () => T): () => T {
18771877

18781878
function event() {
18791879
if (isInvalidExecutionContextForEventFunction()) {
1880-
throw new Error('An event from useEvent was called during render.');
1880+
throw new Error(
1881+
"A function wrapped in useEvent can't be called during rendering.",
1882+
);
18811883
}
18821884
return ref.current.apply(undefined, arguments);
18831885
}

packages/react-reconciler/src/__tests__/useEvent-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ describe('useEvent', () => {
195195

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

201201
// If something throws, we try one more time synchronously in case the error was

packages/react-server/src/ReactFizzHooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ export function useCallback<T>(
505505

506506
function throwOnUseEventCall() {
507507
throw new Error(
508-
'Cannot call a function returned by useEvent during server rendering.',
508+
"A function wrapped in useEvent can't be called during rendering.",
509509
);
510510
}
511511

scripts/error-codes/codes.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@
425425
"437": "the \"precedence\" prop for links to stylesheets expects to receive a string but received something of type \"%s\" instead.",
426426
"438": "An unsupported type was passed to use(): %s",
427427
"439": "We didn't expect to see a forward reference. This is a bug in the React Server.",
428-
"440": "An event from useEvent was called during render.",
429-
"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.",
430-
"442": "Cannot call a function returned by useEvent during server rendering."
431-
}
428+
"440": "A function wrapped in useEvent can't be called during rendering.",
429+
"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."
430+
}

0 commit comments

Comments
 (0)