fix: resume InView observation when triggerOnce is disabled - #782
Draft
ddussi wants to merge 1 commit into
Draft
Conversation
|
|
|
@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. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Hi! I put together a small fix for the lifecycle behavior reported in #781,
along with a regression test.
Summary
<InView>whentriggerOncechangesfrom
truetofalseWhy
After the first intersecting entry,
handleChange()invokes and clears thestored
unobservecallback whentriggerOnceis enabled.componentDidUpdate()already reinitializes observation when severalobserver-related props change, but
triggerOncewas not included in thatcondition. As a result, changing only
triggerOncetofalseleaves themounted node unobserved until another relevant prop changes or the component is
remounted.
This change adds
triggerOnceto the existing reinitialization condition. Itdoes not introduce a new API or a generic resubscribe mechanism.
Fixes #781
Verification
CI=true pnpm test— 7 files, 97 tests passedCI=true pnpm --filter react-intersection-observer exec vitest --coverage—97 tests passed
pnpm --filter react-intersection-observer typecheckpnpm biome ci .pnpm fallow audit --base upstream/main --coverage packages/react-intersection-observer/coverage/coverage-final.jsonpnpm build:allIf runtime updates to
triggerOnceare not intended for the class-based API, orif you would prefer a different lifecycle behavior, I’d be happy to adjust the
approach. Thanks for taking a look!