Skip to content

refactor: share callback-ref observation between hooks#765

Open
thebuilder wants to merge 17 commits into
mainfrom
feat/006-shared-callback-ref-observer-core
Open

refactor: share callback-ref observation between hooks#765
thebuilder wants to merge 17 commits into
mainfrom
feat/006-shared-callback-ref-observer-core

Conversation

@thebuilder

@thebuilder thebuilder commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • move useInView and useOnInView onto one private callback-ref observer core
  • remove the target-element state/effect cycle and the extra useInView attachment commit
  • preserve React 17/18 null-ref cleanup and React 19 returned cleanup, including stale-cleanup protection when targets change
  • publish changing observer callbacks with useInsertionEffect when available; React 17 retains render-time callback publication so synchronous fallback reattachment sees the latest callback
  • keep browser layout timing for detached useInView state resets in the owning hook and use passive effects during SSR
  • cover SSR diagnostics in a dedicated Node Vitest project while keeping component behavior tests in Chromium
  • preserve initialInView as an initial-only option before the first observer notification
  • keep public hook contracts and return shapes unchanged
  • minimally adjust the size budgets after optimization: useInView from 1.3 to 1.36 kB and useOnInView from 1.1 to 1.12 kB

Closes #758.

Bundle sizes

  • InView: 1.36 / 1.5 kB
  • useInView: 1.35 / 1.36 kB
  • useOnInView: 1.11 / 1.12 kB
  • observe: 775 / 900 B

Verification

  • corepack pnpm exec vitest run --coverage — 96 tests passed across the Node and Chromium projects
  • corepack pnpm tsc
  • corepack pnpm exec biome check .
  • corepack pnpm build — tsup, attw, publint, and size-limit passed
  • corepack pnpm run compat:packed -- 17 — packed React 17 consumer build passed
  • CI compatibility matrix covers React 17, 18, 19, and latest

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@vercel

vercel Bot commented Jul 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-intersection-observer Ready Ready Preview, Comment Jul 15, 2026 10:23am

@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/react-intersection-observer@765

commit: 284b09f

@thebuilder thebuilder marked this pull request as ready for review July 14, 2026 12:58
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.

Modernize hook observation with a shared callback-ref core

1 participant