-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inlined components are cleaned up when unmounted
- Loading branch information
1 parent
0f81754
commit 4c08a63
Showing
3 changed files
with
71 additions
and
8 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
33 changes: 33 additions & 0 deletions
33
isolate-react/test/isolateComponent/inline_effect.test.tsx
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,33 @@ | ||
import { describe, test } from 'mocha' | ||
|
||
import React, { useEffect } from 'react' | ||
import { isolateComponentTree } from '../../src/isolateComponent' | ||
import assert from 'node:assert' | ||
|
||
describe('inline effect cleanup', () => { | ||
test('effect cleanup is run for unmounted inlined component', () => { | ||
let calls = [] as string[] | ||
|
||
const EffectTracker = ({ tag }: { tag: string }) => { | ||
useEffect(() => { | ||
calls.push(`mount ${tag}`) | ||
return () => { | ||
calls.push(`unmount ${tag}`) | ||
} | ||
}, []) | ||
return <div>{tag}</div> | ||
} | ||
|
||
const Wrapper = ({ keys }: { keys: string[] }) => ( | ||
<div> | ||
{keys.map((k) => ( | ||
<EffectTracker key={k} tag={k} /> | ||
))} | ||
</div> | ||
) | ||
|
||
const isolated = isolateComponentTree(<Wrapper keys={['a']} />) | ||
isolated.setProps({ keys: [] }) | ||
assert.deepEqual(calls, ['mount a', 'unmount a']) | ||
}) | ||
}) |
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