diff --git a/packages/fiber/src/core/renderer.ts b/packages/fiber/src/core/renderer.ts index 6103141565..3963e7fcff 100644 --- a/packages/fiber/src/core/renderer.ts +++ b/packages/fiber/src/core/renderer.ts @@ -226,13 +226,20 @@ function createRenderer(_roots: Map, _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) diff --git a/packages/fiber/tests/core/renderer.test.tsx b/packages/fiber/tests/core/renderer.test.tsx index f970670a38..df07318fb5 100644 --- a/packages/fiber/tests/core/renderer.test.tsx +++ b/packages/fiber/tests/core/renderer.test.tsx @@ -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()