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

add shouldRevalidate export to root loaders #1237

Merged
merged 1 commit into from
Aug 18, 2023

Conversation

juanpprieto
Copy link
Contributor

@juanpprieto juanpprieto commented Aug 16, 2023

WHY are these changes introduced?

Remix revalidates layouts and routes when the url searchParams are added, removed or changed. This means that all our product page navigations, paginated collection pages and changing product variants were causing the root layout loader to revalidate.

WHAT is this pull request doing?

This PR limits the root loaders to only ever revalidate when a mutation is performed. This includes all cart and account POST/PUT/PATCH requests.

HOW to test your changes?

Console log inside a root loader and navigate into and out of route which include a change in the url. The root loader should only log on first page load and when a mutation e.g add to cart happens.

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes

@wizardlyhel
Copy link
Contributor

We don't need the useRevaidator check?

  // user is doing a manual revalidation via useRevalidator
  if (currentUrl.toString() === nextUrl.toString()) {
    return true;
  }

add shouldRevalidate to the skeleton

add shouldRevalidate to avoid root re-renders

add changeset

clear logs

.
@juanpprieto
Copy link
Contributor Author

juanpprieto commented Aug 18, 2023

We don't need the useRevaidator check?

  // user is doing a manual revalidation via useRevalidator
  if (currentUrl.toString() === nextUrl.toString()) {
    return true;
  }

Thanks @wizardlyhel. It's back in. I took it out as I was seeing some odd revalidations in the PDP, but triple checked and now they are not happening 🙏🏼

@juanpprieto juanpprieto merged commit 632a7a3 into 2023-07 Aug 18, 2023
@juanpprieto juanpprieto deleted the juanpprieto/add-shouldRevalidate branch August 18, 2023 21:12
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.

3 participants