-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Splitter state is not saved in StrictMode #3413
Comments
I can take a look at this. Thanks for the detailed report! |
I do not think it is related only to StrictMode. It is always overwritten on rerender. Open the reproducer URL and then the Developer Tools. I was going to propose an alternative fix, which I think avoids calling restoreState on each render. if (props.children && props.children.length) {
let initialized = isStateful && panelSizes.current; // this line is changed
if (isStateful && !mounted.current) {
initialized = restoreState();
} |
@kalinkrustev sure thing please submit the PR. |
Sorry, I did not notice the switch from React.useEffect to useMountEffect, so probably there is not restoreState on each render. Still I think a better fix is to See #3482. I have not tested it yet, but it should work better than the original fix and I think it is a simpler approach. |
Looks good there is one build error but let me know how your testing goes. |
Describe the bug
Splitter sometimes overwrites local storage data.
If using <React.StrictMode> the data gets reset on refresh.
If removing StrictMode, then it works as intended.
Reproducer
https://codesandbox.io/s/primereact-test-forked-p647y5?file=/src/index.js
PrimeReact version
8.6.1
React version
18.x
Language
TypeScript
Build / Runtime
Create React App (CRA)
Browser(s)
No response
Steps to reproduce the behavior
As shown in the codesandbox, if you use StrictMode then stored data gets overwritten on refresh.
If you remove the StrictMode tags, then you can refresh and it correctly remembers you data.
Expected behavior
Don't overwrite data regardless of whether or not StrictMode is used.
The text was updated successfully, but these errors were encountered: