-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Fix URL creation with memory history #9814
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
Conversation
🦋 Changeset detectedLatest commit: 94efa1a The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
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 |
| @@ -1,7 +1,3 @@ | |||
| /** | |||
| * @jest-environment ./__tests__/custom-environment.js | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure why we had 2 ways of doing this but I moved the custom environment stuff into setup.ts
| /** | ||
| * @jest-environment node | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because tests by default run in jsdom, we didn't catch this regression since window was defined during test runs when using a memory history. Now we have this standalone file that runs directly in node to catch those
|
|
||
| if (!globalThis.AbortController) { | ||
| // @ts-expect-error | ||
| globalThis.AbortController = NodeAbortController; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed for the new node test run
| globalThis.TextEncoder = NodeTextEncoder; | ||
| // @ts-expect-error | ||
| globalThis.TextDecoder = NodeTextDecoder; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied over from the deleted custom environment
| // Check if this an external redirect that goes to a new origin | ||
| if (typeof window?.location !== "undefined") { | ||
| let newOrigin = createClientSideURL(redirect.location).origin; | ||
| let newOrigin = init.history.createURL(redirect.location).origin; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All (non-static-handler) URL creation now uses the history.createURL function
| return typeof to === "string" ? to : createPath(to); | ||
| createHref, | ||
| createURL(to) { | ||
| return new URL(createHref(to), "http://localhost"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memory histories will use localhost as the URL base
Fixing an oversight from https://github.com/remix-run/react-router/pull/9682/files#r1040159998. Now
URLcreation is driven byhistory.createURLso we have clear boundaries between memory versus browser cases.Closes #9796