Skip to content

fix: resume InView observation when triggerOnce is disabled - #782

Draft
ddussi wants to merge 1 commit into
thebuilder:mainfrom
ddussi:fix/inview-trigger-once-resume
Draft

fix: resume InView observation when triggerOnce is disabled#782
ddussi wants to merge 1 commit into
thebuilder:mainfrom
ddussi:fix/inview-trigger-once-resume

Conversation

@ddussi

@ddussi ddussi commented Aug 11, 2026

Copy link
Copy Markdown

Hi! I put together a small fix for the lifecycle behavior reported in #781,
along with a regression test.

Summary

  • resume observation in the class-based <InView> when triggerOnce changes
    from true to false
  • add regression coverage for this stopped-observer lifecycle

Why

After the first intersecting entry, handleChange() invokes and clears the
stored unobserve callback when triggerOnce is enabled.

componentDidUpdate() already reinitializes observation when several
observer-related props change, but triggerOnce was not included in that
condition. As a result, changing only triggerOnce to false leaves the
mounted node unobserved until another relevant prop changes or the component is
remounted.

This change adds triggerOnce to the existing reinitialization condition. It
does not introduce a new API or a generic resubscribe mechanism.

Fixes #781

Verification

  • CI=true pnpm test — 7 files, 97 tests passed
  • CI=true pnpm --filter react-intersection-observer exec vitest --coverage
    97 tests passed
  • pnpm --filter react-intersection-observer typecheck
  • pnpm biome ci .
  • pnpm fallow audit --base upstream/main --coverage packages/react-intersection-observer/coverage/coverage-final.json
  • pnpm build:all

If runtime updates to triggerOnce are not intended for the class-based API, or
if you would prefer a different lifecycle behavior, I’d be happy to adjust the
approach. Thanks for taking a look!

@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 Aug 11, 2026

Copy link
Copy Markdown

@ddussi is attempting to deploy a commit to the Daniel Schmidt's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Aug 11, 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 Aug 11, 2026 7:12am

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.

InView does not resume observing when triggerOnce changes to false

1 participant