Skip to content

Commit fe246c9

Browse files
committed
Remove invokeGuardedCallback and replay trick
1 parent 706d95f commit fe246c9

File tree

48 files changed

+209
-1251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+209
-1251
lines changed

packages/react-cache/src/__tests__/ReactCacheOld-test.internal.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
let ReactCache;
1313
let createResource;
1414
let React;
15-
let ReactFeatureFlags;
1615
let ReactNoop;
1716
let Scheduler;
1817
let Suspense;
@@ -27,9 +26,6 @@ describe('ReactCache', () => {
2726
beforeEach(() => {
2827
jest.resetModules();
2928

30-
ReactFeatureFlags = require('shared/ReactFeatureFlags');
31-
32-
ReactFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
3329
React = require('react');
3430
Suspense = React.Suspense;
3531
ReactCache = require('react-cache');

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,13 +1231,6 @@ describe('ReactCompositeComponent', () => {
12311231
});
12321232
}).toThrow();
12331233
}).toErrorDev([
1234-
// Expect two errors because invokeGuardedCallback will dispatch an error event,
1235-
// Causing the warning to be logged again.
1236-
'Warning: No `render` method found on the RenderTextInvalidConstructor instance: ' +
1237-
'did you accidentally return an object from the constructor?',
1238-
'Warning: No `render` method found on the RenderTextInvalidConstructor instance: ' +
1239-
'did you accidentally return an object from the constructor?',
1240-
// And then two more because we retry errors.
12411234
'Warning: No `render` method found on the RenderTextInvalidConstructor instance: ' +
12421235
'did you accidentally return an object from the constructor?',
12431236
'Warning: No `render` method found on the RenderTextInvalidConstructor instance: ' +
@@ -1278,14 +1271,6 @@ describe('ReactCompositeComponent', () => {
12781271
});
12791272
}).toThrow();
12801273
}).toErrorDev([
1281-
// Expect two errors because invokeGuardedCallback will dispatch an error event,
1282-
// Causing the warning to be logged again.
1283-
'Warning: No `render` method found on the RenderTestUndefinedRender instance: ' +
1284-
'you may have forgotten to define `render`.',
1285-
'Warning: No `render` method found on the RenderTestUndefinedRender instance: ' +
1286-
'you may have forgotten to define `render`.',
1287-
1288-
// And then two more because we retry errors.
12891274
'Warning: No `render` method found on the RenderTestUndefinedRender instance: ' +
12901275
'you may have forgotten to define `render`.',
12911276
'Warning: No `render` method found on the RenderTestUndefinedRender instance: ' +

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

Lines changed: 25 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -82,64 +82,25 @@ describe('ReactDOMConsoleErrorReporting', () => {
8282
);
8383
});
8484

85-
if (__DEV__) {
86-
expect(windowOnError.mock.calls).toEqual([
87-
[
88-
// Reported because we're in a browser click event:
89-
expect.objectContaining({
90-
message: 'Boom',
91-
}),
92-
],
93-
[
94-
// This one is jsdom-only. Real browser deduplicates it.
95-
// (In DEV, we have a nested event due to guarded callback.)
96-
expect.objectContaining({
97-
message: 'Boom',
98-
}),
99-
],
100-
]);
101-
expect(console.error.mock.calls).toEqual([
102-
[
103-
// Reported because we're in a browser click event:
104-
expect.objectContaining({
105-
detail: expect.objectContaining({
106-
message: 'Boom',
107-
}),
108-
type: 'unhandled exception',
109-
}),
110-
],
111-
[
112-
// This one is jsdom-only. Real browser deduplicates it.
113-
// (In DEV, we have a nested event due to guarded callback.)
114-
expect.objectContaining({
115-
detail: expect.objectContaining({
116-
message: 'Boom',
117-
}),
118-
type: 'unhandled exception',
119-
}),
120-
],
121-
]);
122-
} else {
123-
expect(windowOnError.mock.calls).toEqual([
124-
[
125-
// Reported because we're in a browser click event:
126-
expect.objectContaining({
85+
expect(windowOnError.mock.calls).toEqual([
86+
[
87+
// Reported because we're in a browser click event:
88+
expect.objectContaining({
89+
message: 'Boom',
90+
}),
91+
],
92+
]);
93+
expect(console.error.mock.calls).toEqual([
94+
[
95+
// Reported because we're in a browser click event:
96+
expect.objectContaining({
97+
detail: expect.objectContaining({
12798
message: 'Boom',
12899
}),
129-
],
130-
]);
131-
expect(console.error.mock.calls).toEqual([
132-
[
133-
// Reported because we're in a browser click event:
134-
expect.objectContaining({
135-
detail: expect.objectContaining({
136-
message: 'Boom',
137-
}),
138-
type: 'unhandled exception',
139-
}),
140-
],
141-
]);
142-
}
100+
type: 'unhandled exception',
101+
}),
102+
],
103+
]);
143104

144105
// Check next render doesn't throw.
145106
windowOnError.mockReset();
@@ -168,41 +129,8 @@ describe('ReactDOMConsoleErrorReporting', () => {
168129
});
169130

170131
if (__DEV__) {
171-
expect(windowOnError.mock.calls).toEqual([
172-
[
173-
// Reported due to guarded callback:
174-
expect.objectContaining({
175-
message: 'Boom',
176-
}),
177-
],
178-
[
179-
// This is only duplicated with createRoot
180-
// because it retries once with a sync render.
181-
expect.objectContaining({
182-
message: 'Boom',
183-
}),
184-
],
185-
]);
132+
expect(windowOnError.mock.calls).toEqual([]);
186133
expect(console.error.mock.calls).toEqual([
187-
[
188-
// Reported due to the guarded callback:
189-
expect.objectContaining({
190-
detail: expect.objectContaining({
191-
message: 'Boom',
192-
}),
193-
type: 'unhandled exception',
194-
}),
195-
],
196-
[
197-
// This is only duplicated with createRoot
198-
// because it retries once with a sync render.
199-
expect.objectContaining({
200-
detail: expect.objectContaining({
201-
message: 'Boom',
202-
}),
203-
type: 'unhandled exception',
204-
}),
205-
],
206134
[
207135
// Addendum by React:
208136
expect.stringContaining(
@@ -254,41 +182,8 @@ describe('ReactDOMConsoleErrorReporting', () => {
254182
});
255183

256184
if (__DEV__) {
257-
expect(windowOnError.mock.calls).toEqual([
258-
[
259-
// Reported due to guarded callback:
260-
expect.objectContaining({
261-
message: 'Boom',
262-
}),
263-
],
264-
[
265-
// This is only duplicated with createRoot
266-
// because it retries once with a sync render.
267-
expect.objectContaining({
268-
message: 'Boom',
269-
}),
270-
],
271-
]);
185+
expect(windowOnError.mock.calls).toEqual([]);
272186
expect(console.error.mock.calls).toEqual([
273-
[
274-
// Reported by jsdom due to the guarded callback:
275-
expect.objectContaining({
276-
detail: expect.objectContaining({
277-
message: 'Boom',
278-
}),
279-
type: 'unhandled exception',
280-
}),
281-
],
282-
[
283-
// This is only duplicated with createRoot
284-
// because it retries once with a sync render.
285-
expect.objectContaining({
286-
detail: expect.objectContaining({
287-
message: 'Boom',
288-
}),
289-
type: 'unhandled exception',
290-
}),
291-
],
292187
[
293188
// Addendum by React:
294189
expect.stringContaining(
@@ -340,24 +235,8 @@ describe('ReactDOMConsoleErrorReporting', () => {
340235
});
341236

342237
if (__DEV__) {
343-
expect(windowOnError.mock.calls).toEqual([
344-
[
345-
// Reported due to guarded callback:
346-
expect.objectContaining({
347-
message: 'Boom',
348-
}),
349-
],
350-
]);
238+
expect(windowOnError.mock.calls).toEqual([]);
351239
expect(console.error.mock.calls).toEqual([
352-
[
353-
// Reported due to the guarded callback:
354-
expect.objectContaining({
355-
detail: expect.objectContaining({
356-
message: 'Boom',
357-
}),
358-
type: 'unhandled exception',
359-
}),
360-
],
361240
[
362241
// Addendum by React:
363242
expect.stringContaining(
@@ -412,24 +291,8 @@ describe('ReactDOMConsoleErrorReporting', () => {
412291
});
413292

414293
if (__DEV__) {
415-
expect(windowOnError.mock.calls).toEqual([
416-
[
417-
// Reported due to guarded callback:
418-
expect.objectContaining({
419-
message: 'Boom',
420-
}),
421-
],
422-
]);
294+
expect(windowOnError.mock.calls).toEqual([]);
423295
expect(console.error.mock.calls).toEqual([
424-
[
425-
// Reported by jsdom due to the guarded callback:
426-
expect.objectContaining({
427-
detail: expect.objectContaining({
428-
message: 'Boom',
429-
}),
430-
type: 'unhandled exception',
431-
}),
432-
],
433296
[
434297
// Addendum by React:
435298
expect.stringContaining(
@@ -438,7 +301,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
438301
],
439302
]);
440303
} else {
441-
// The top-level error was caught with try/catch, and there's no guarded callback,
304+
// The top-level error was caught with try/catch,
442305
// so in production we don't see an error event.
443306
expect(windowOnError.mock.calls).toEqual([]);
444307
expect(console.error.mock.calls).toEqual([
@@ -481,24 +344,8 @@ describe('ReactDOMConsoleErrorReporting', () => {
481344
});
482345

483346
if (__DEV__) {
484-
expect(windowOnError.mock.calls).toEqual([
485-
[
486-
// Reported due to guarded callback:
487-
expect.objectContaining({
488-
message: 'Boom',
489-
}),
490-
],
491-
]);
347+
expect(windowOnError.mock.calls).toEqual([]);
492348
expect(console.error.mock.calls).toEqual([
493-
[
494-
// Reported due to the guarded callback:
495-
expect.objectContaining({
496-
detail: expect.objectContaining({
497-
message: 'Boom',
498-
}),
499-
type: 'unhandled exception',
500-
}),
501-
],
502349
[
503350
// Addendum by React:
504351
expect.stringContaining(
@@ -507,7 +354,7 @@ describe('ReactDOMConsoleErrorReporting', () => {
507354
],
508355
]);
509356
} else {
510-
// The top-level error was caught with try/catch, and there's no guarded callback,
357+
// The top-level error was caught with try/catch,
511358
// so in production we don't see an error event.
512359
expect(windowOnError.mock.calls).toEqual([]);
513360
expect(console.error.mock.calls).toEqual([
@@ -553,24 +400,8 @@ describe('ReactDOMConsoleErrorReporting', () => {
553400
});
554401

555402
if (__DEV__) {
556-
expect(windowOnError.mock.calls).toEqual([
557-
[
558-
// Reported due to guarded callback:
559-
expect.objectContaining({
560-
message: 'Boom',
561-
}),
562-
],
563-
]);
403+
expect(windowOnError.mock.calls).toEqual([]);
564404
expect(console.error.mock.calls).toEqual([
565-
[
566-
// Reported by jsdom due to the guarded callback:
567-
expect.objectContaining({
568-
detail: expect.objectContaining({
569-
message: 'Boom',
570-
}),
571-
type: 'unhandled exception',
572-
}),
573-
],
574405
[
575406
// Addendum by React:
576407
expect.stringContaining(

0 commit comments

Comments
 (0)