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

Omit search part of path when detecting if the route changed after downloading asset bundles #6707

Merged
merged 5 commits into from
Jun 29, 2023

Conversation

n8agrin
Copy link
Contributor

@n8agrin n8agrin commented Jun 27, 2023

Resolves #6703

Previous implementation used the pathname and search parts of a url to determine if route changed, which causes some conflict when CDNs / cache proxies are placed between the Remix app and the client. This change allows remix to reload the page if only the path changes. There may be some issues with how loaders are handled when configured behind a CDN, since Remix expects to trigger loaders when the search part of a url changes, but the total impact here is dependent on how a developer is configuring the network topology on top of a Remix server.

Closes: #6703

  • Docs
  • Tests

Testing Strategy:

…wnloading asset bundles

Resolves remix-run#6703

Previous implementation used the pathname and search parts of a url to determine if route changed, which causes some conflict when CDNs / cache proxies are placed between the Remix app and the client. This change allows remix to reload the page if only the path changes. There may be some issues with how loaders are handled when configured behind a CDN, since Remix expects to trigger loaders when the search part of a url changes, but the total impact here is dependent on how a developer is configuring the network topology on top of a Remix server.
@changeset-bot
Copy link

changeset-bot bot commented Jun 27, 2023

🦋 Changeset detected

Latest commit: 9c6cf2f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 18 packages
Name Type
@remix-run/react Patch
@remix-run/server-runtime Patch
@remix-run/testing Patch
@remix-run/cloudflare Patch
@remix-run/deno Patch
@remix-run/dev Patch
@remix-run/node Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
create-remix Patch
@remix-run/architect Patch
@remix-run/express Patch
@remix-run/netlify Patch
@remix-run/serve Patch
@remix-run/vercel Patch
remix Patch
@remix-run/css-bundle Patch
@remix-run/eslint-config Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@n8agrin
Copy link
Contributor Author

n8agrin commented Jun 27, 2023

@yarbsemaj @brophdawg11 Please see the note in the description. I am concerned about the impact this might have on loaders which expect specific search params to function correctly. I'm also not 100% sure I understand your use case @yarbsemaj.

Please confirm the issue is something like:

  • user visits /foo?a=yes
  • cdn caches /foo?a=yes
  • user visits /foo
  • cdn loads cached assets including the serialized /foo?a=yes string
  • remix redirects to /foo
  • 💥 the cycle repeats itself

I suspect the better solution here might be to change your cdn cache policy to ignore search params in the url.

@n8agrin n8agrin mentioned this pull request Jun 27, 2023
1 task
@BillBrower-Shopify
Copy link

BillBrower-Shopify commented Jun 28, 2023

This ends up causing an infinite reload cycle for urls without query params when I test it as a patch on top of Remix 1.18.0 in our project.

Edit: The infinite reload was actually caused by the patch being correctly applied to @remix-run/server-runtime but not @remix-run/react. After correcting the @remix-run/react patch this works as expected and there is no infinite reload issue.

@yarbsemaj
Copy link

@n8agrin Unfortunately this is not an option in our setup, and i imagine many other as well

@n8agrin
Copy link
Contributor Author

n8agrin commented Jun 28, 2023

@yarbsemaj ok. I’m not a fan of this approach. Closing. @brophdawg11 is the expert here as far as I can tell. I’ll wait for @brophdawg11 to weigh in

@n8agrin n8agrin closed this Jun 28, 2023
@brophdawg11
Copy link
Contributor

Unfortunately this is not an option in our setup

@yarbsemaj This is a bit ambiguous to me. Is the pathname-only comparion implemented in this PR not an option for your setup?

Or were you referring to the solution suggested by @n8agrin above:

I suspect the better solution here might be to change your cdn cache policy to ignore search params in the url.

From the description of your issue in #6703 it sounds like the root cause of your issue is the inclusion of search params in the hydration check, and that only comparing pathnames would suffice?

@brophdawg11
Copy link
Contributor

I'm going to re-open this since I do believe this is the right solution to avoid reloads when CDN's ignore certain search parameters. I confirmed with @BillBrower-Shopify that this fix resolves the issue they are seeing which is due to the CDN only respecting certain search params. While this is sort of a non-standard HTTP caching approach, I believe it's probably used pretty frequently.

Since the underlying issue here is a mismatch in matched routes on the server and the client, and route matching only cares about the pathname, I believe this is how the original implementation should have been anyway.

@brophdawg11 brophdawg11 reopened this Jun 29, 2023
@n8agrin
Copy link
Contributor Author

n8agrin commented Jun 29, 2023

Thanks for weighing in @brophdawg11

@brophdawg11 brophdawg11 changed the base branch from main to release-next June 29, 2023 18:55
@@ -230,7 +230,7 @@ describe("remix CLI", () => {
await interactWithShell(proc, [
{ question: /Where.*create.*app/i, type: [projectDir, ENTER] },
{ question: /What type of app/i, answer: /basics/i },
{ question: /Where.*deploy/i, answer: /express/i },
{ question: /Where.*deploy/i, answer: /remix/i },
Copy link
Contributor

Choose a reason for hiding this comment

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

Ignore this unit test fix - this was fixed in dev and cherry-picked into main and release-next. This branch has the main SHA since I merged main in - but this code is already in release-next so it's not actually changing anything.

@@ -335,7 +335,7 @@ async function handleDocumentRequestRR(
...entryContext,
staticHandlerContext: context,
serverHandoffString: createServerHandoffString({
url: context.location.pathname + context.location.search,
url: context.location.pathname,
Copy link
Contributor

Choose a reason for hiding this comment

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

Keeping the url name in this handoff string since it's technically exposed to users via EntryContext.serverHandoffString and window.__remixContext so just in case anyone is accessing it.

@@ -335,7 +335,7 @@ async function handleDocumentRequestRR(
...entryContext,
staticHandlerContext: context,
serverHandoffString: createServerHandoffString({
url: context.location.pathname + context.location.search,
pathname: context.location.pathname,
Copy link
Member

Choose a reason for hiding this comment

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

Do we consider this handoff format public API? If so can we not re-name the property here and re-purpose the "url" name?

Copy link
Contributor

Choose a reason for hiding this comment

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

Updated in 9c6cf2f

@brophdawg11 brophdawg11 merged commit c8db245 into remix-run:release-next Jun 29, 2023
9 checks passed
@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version 1.18.1-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v0.0.0-nightly-0657c16-20230630 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@yarbsemaj
Copy link

yarbsemaj commented Jun 30, 2023

@brophdawg11

Unfortunately this is not an option in our setup

@yarbsemaj This is a bit ambiguous to me. Is the pathname-only comparion implemented in this PR not an option for your setup?

Sorry for the confusion, i was referring to this comment about updating our CDN Policy, this is due to us needing access to a full range of query parameters on certan, arbitrary routes that can not easily be modeled with cache behaviours.

I suspect the better solution here might be to change your cdn cache policy to ignore search params in the url.

@brophdawg11
Copy link
Contributor

@yarbsemaj No worries! Can you confirm if 1.18.1-pre.0 fixes your issue?

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version 1.18.1-pre.2 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version 1.18.1 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CDN Causing infinite reload
6 participants