Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: strict mode and missing context value #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
raRaRa wants to merge 1 commit into jscottsmith:master from raRaRa:master

Conversation

Copy link

@raRaRa raRaRa commented Nov 19, 2023
edited
Loading

This PR fixes #233 #227 and #221

The issue was that the controller could become null in between renders, e.g. when React is in strict mode. Strict mode in React makes all useEffects run twice, to make sure they don't have any memory leaks, etc. More can be read here: https://legacy.reactjs.org/docs/strict-mode.html#ensuring-reusable-state

What happened is that the last useEffect that handles unmount got called twice, thus the controller became null. This is not a NextJS issue, but React Strict mode issue (strict mode with useEffect came in React 18). Because of this, the useEffect should always handle both mount & unmount (never assume that unmount gets called once).

With this PR I never make the controller null, instead I just disable the controller which should clean all the event listeners. Please correct me if I'm wrong.

I've tested these changes in NextJS app router and it seems to fix all of the issues.

AseWhy reacted with thumbs up emoji
Copy link

vercel bot commented Nov 19, 2023
edited
Loading

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-scroll-parallax ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 19, 2023 8:04pm

Copy link

Can confirm this fixed it for me in NextJS 14

raRaRa reacted with thumbs up emoji

Copy link
Owner

Thanks for digging into this -- was helpful to see and definitely related to strict mode, but can't replace the call to destroy with disableParallaxController since that only disables effects.

I believe the problem was mainly around how the useRef was used, it's was creating a new controller each render, and setting it to null in the cleanup as you said.

I tested this on Next 14, and it seems to fix it.

I'll publish it later this evening.

jscottsmith added a commit that referenced this pull request Nov 21, 2023
- related to strict mode issues #233 #227 and #221
- credit to @raRaRa for #234 
Copy link
Owner

Published v3.4.4

Copy link
Author

raRaRa commented Nov 21, 2023

Closing this PR because the destroy was required. Ref: #235

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Could not find react-scroll-parallax context value. Please ensure the component is wrapped in a <ParallaxProvider>

AltStyle によって変換されたページ (->オリジナル) /