Skip to content
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

Don't remount wrap components when navigating within Set #9312

Merged
merged 10 commits into from
Oct 25, 2023

Conversation

Tobbe
Copy link
Member

@Tobbe Tobbe commented Oct 18, 2023

<Router>
  <Route path="/" page={HomePage} name="home" />
  <Set wrap={SetContextProvider}>
    <Route path="/ctx-1-page" page={Ctx1Page} name="ctx1" />
    <Route path="/ctx-2-page" page={Ctx2Page} name="ctx2" />
    <Set wrap={SetContextProvider}>
      <Route path="/ctx-3-page" page={Ctx3Page} name="ctx3" />
    </Set>
  </Set>
  <Set wrap={SetContextProvider}>
    <Route path="/ctx-4-page" page={Ctx4Page} name="ctx4" />
  </Set>
</Router>

Given the router above here what we want to happen:
User navigates from / to /ctx-1-page: SetContextProvider is mounted
User continue navigating to /ctx-2-page: SetContextProvider is not remounted
User continue navigating to /ctx-3-page: A new SetContextProvider is mounted. The old one stays mounted too.
User navigates back to /ctx-1-page: The new SetContextProvider that was mounted is unmounted. The original SetContextProvider is still mounted (and has not been remounted).
User navigates to /ctx-4-page: The original SetContextProvider is finally unmounted and a new one is mounted instead.

This PR makes the above work as expected by assigning each Set a unique id and then using that id as a key when rendering all the wrapper components. So even though, in the case where the user navigates from /ctx-2-page to /ctx-3-page, the original SetContextProvider is rerendered React knows it's the same component (because the key is the same) so it's never unmounted.

Fixes #9105

@Tobbe Tobbe marked this pull request as ready for review October 20, 2023 12:04
@Tobbe Tobbe added the release:fix This PR is a fix label Oct 20, 2023
@Tobbe Tobbe added this to the next-release-patch milestone Oct 20, 2023
Copy link
Contributor

@KrisCoulson KrisCoulson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Only small suggestion

@Tobbe Tobbe enabled auto-merge (squash) October 25, 2023 04:50
@Tobbe Tobbe merged commit 4c5a3eb into redwoodjs:main Oct 25, 2023
32 checks passed
@Tobbe Tobbe deleted the tobbe-set-wrap-remount branch October 26, 2023 06:11
@jtoar jtoar modified the milestones: next-release-patch, v6.4.0 Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:fix This PR is a fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug?]: Remount of parent <Set /> on navigation leads to flickering
3 participants