Skip to content

Commit

Permalink
chore: flush scheduler in testing
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Nov 6, 2023
1 parent f2b430c commit 3708229
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 9 additions & 2 deletions packages/fiber/src/core/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,20 @@ function createRenderer<TCanvas>(_roots: Map<TCanvas, Root>, _getEventPriority?:

// Dispose item whenever the reconciler feels like it
if (shouldDispose && child.dispose && child.type !== 'Scene') {
scheduleCallback(idlePriority, () => {
const callback = () => {
try {
child.dispose()
} catch (e) {
/* ... */
}
})
}

// Schedule async at runtime, flush sync in testing
if (typeof IS_REACT_ACT_ENVIRONMENT === 'undefined') {
scheduleCallback(idlePriority, callback)
} else {
callback()
}
}

invalidateInstance(parentInstance)
Expand Down
3 changes: 1 addition & 2 deletions packages/fiber/tests/core/renderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -963,8 +963,7 @@ describe('renderer', () => {
expect(ref.current!.userData.attach).toBe(attachedChild.current)
})

// TODO: scheduler isn't flushed during testing which prevents disposal
it.skip('should not recursively dispose of attached primitives', async () => {
it('should not recursively dispose of attached primitives', async () => {
const meshDispose = jest.fn()
const primitiveDispose = jest.fn()

Expand Down

0 comments on commit 3708229

Please sign in to comment.