-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deletion effects should fire parent -> child (#20584)
* Test: Deletion effects should fire parent -> child Regression in new effect implementation * Fix passive deletion effect ordering
- Loading branch information
Showing
3 changed files
with
100 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
packages/react-reconciler/src/__tests__/ReactEffectOrdering-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails react-core | ||
* @jest-environment node | ||
*/ | ||
|
||
/* eslint-disable no-func-assign */ | ||
|
||
'use strict'; | ||
|
||
let React; | ||
let ReactNoop; | ||
let Scheduler; | ||
let useEffect; | ||
let useLayoutEffect; | ||
|
||
describe('ReactHooksWithNoopRenderer', () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
jest.useFakeTimers(); | ||
|
||
React = require('react'); | ||
ReactNoop = require('react-noop-renderer'); | ||
Scheduler = require('scheduler'); | ||
useEffect = React.useEffect; | ||
useLayoutEffect = React.useLayoutEffect; | ||
}); | ||
|
||
test('layout unmmouts on deletion are fired in parent -> child order', async () => { | ||
const root = ReactNoop.createRoot(); | ||
|
||
function Parent() { | ||
useLayoutEffect(() => { | ||
return () => Scheduler.unstable_yieldValue('Unmount parent'); | ||
}); | ||
return <Child />; | ||
} | ||
|
||
function Child() { | ||
useLayoutEffect(() => { | ||
return () => Scheduler.unstable_yieldValue('Unmount child'); | ||
}); | ||
return 'Child'; | ||
} | ||
|
||
await ReactNoop.act(async () => { | ||
root.render(<Parent />); | ||
}); | ||
expect(root).toMatchRenderedOutput('Child'); | ||
await ReactNoop.act(async () => { | ||
root.render(null); | ||
}); | ||
expect(Scheduler).toHaveYielded(['Unmount parent', 'Unmount child']); | ||
}); | ||
|
||
test('passive unmmouts on deletion are fired in parent -> child order', async () => { | ||
const root = ReactNoop.createRoot(); | ||
|
||
function Parent() { | ||
useEffect(() => { | ||
return () => Scheduler.unstable_yieldValue('Unmount parent'); | ||
}); | ||
return <Child />; | ||
} | ||
|
||
function Child() { | ||
useEffect(() => { | ||
return () => Scheduler.unstable_yieldValue('Unmount child'); | ||
}); | ||
return 'Child'; | ||
} | ||
|
||
await ReactNoop.act(async () => { | ||
root.render(<Parent />); | ||
}); | ||
expect(root).toMatchRenderedOutput('Child'); | ||
await ReactNoop.act(async () => { | ||
root.render(null); | ||
}); | ||
expect(Scheduler).toHaveYielded(['Unmount parent', 'Unmount child']); | ||
}); | ||
}); |