Fix callback ref cleanup compatibility across React 17–19#760
Merged
Conversation
|
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
thebuilder
marked this pull request as ready for review
July 14, 2026 10:41
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ref(null)cleanup pathWhy
React 19 supports cleanup functions returned from callback refs, but React 17 and 18 treat that return value as invalid and emit diagnostics.
useOnInViewreturned its cleanup unconditionally even though all three React majors are supported peers.The private version gate is deliberately limited to
19.because that is the newest declared and tested peer major. This keeps React 19 merged-ref cleanup composition while falling back conservatively for older, future, and malformed version strings.The packed fixture only verifies the consumer packaging and bundler boundary. Runtime cleanup and diagnostics are exercised in real Chromium by the existing Vitest Browser suite, avoiding a separate JSDOM runtime harness.
Fixes #755.
Verification
corepack pnpm buildcorepack pnpm exec vitest run— 77 tests passedcorepack pnpm run compat:packed -- 17corepack pnpm run compat:packed -- 18corepack pnpm run compat:packed -- 19corepack pnpm exec tsc --noEmitcorepack pnpm exec biome check src/useOnInView.tsx src/refCleanupSupport.ts src/__tests__/useOnInView.test.tsx scripts/compat fixtures/react-compat package.jsoncorepack pnpm dlx github-actionlint .github/workflows/test.ymluseOnInView: 1.06 kB / 1.1 kB size limit