Skip to content

fix(hooks): avoid static useInsertionEffect imports#960

Merged
usefulthink merged 2 commits intovisgl:mainfrom
officialasishkumar:fix/use-effect-event-build-compat
Apr 9, 2026
Merged

fix(hooks): avoid static useInsertionEffect imports#960
usefulthink merged 2 commits intovisgl:mainfrom
officialasishkumar:fix/use-effect-event-build-compat

Conversation

@officialasishkumar
Copy link
Copy Markdown
Contributor

Summary

  • stop statically importing useInsertionEffect so React 16/17 builds can resolve the module cleanly
  • keep the React 18+ fast path by reading useInsertionEffect dynamically and falling back to useLayoutEffect
  • add a bundler regression that verifies the hook still bundles when react does not export useInsertionEffect

Testing

  • npx jest src/hooks/__tests__/use-effect-event.test.ts --runInBand
  • npm run test:tsc
  • npx eslint src/hooks/use-effect-event.ts src/hooks/__tests__/use-effect-event.test.ts

Closes #957.

Copy link
Copy Markdown
Collaborator

@usefulthink usefulthink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution, I can see a lot of thought went into this.

I think the test is a bit over the top for this, it essentially just makes sure that this exact change won't be reverted, and introduces a lot of unwanted dependencies (the test-suite shouldn't need the typescript compiler and rollup to run, even if they are coincidentally installed).

officialasishkumar and others added 2 commits April 9, 2026 05:34
Address review feedback:
- Replace Reflect.get() with direct property access (React.useInsertionEffect ?? useLayoutEffect)
- Remove bundler regression test that introduced heavy test dependencies

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@officialasishkumar officialasishkumar force-pushed the fix/use-effect-event-build-compat branch from e16ac85 to 9a4ab5e Compare April 9, 2026 05:36
Copy link
Copy Markdown
Collaborator

@usefulthink usefulthink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@usefulthink usefulthink merged commit f2870c1 into visgl:main Apr 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Build failure when importing useInsertionEffect in React <18 despite fallback to useLayoutEffect

2 participants