-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
fix(rsc): normalize double slashes in manifest URLs #14586
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
Open
swarnim02
wants to merge
7
commits into
remix-run:main
Choose a base branch
from
swarnim02:fix/rsc-double-slashes-issue-14583
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+45
−5
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5c8fa80
fix(rsc): normalize double slashes in manifest URLs
swarnim02 f95714b
Update contributors.yml
swarnim02 7e3ff14
add changeset
swarnim02 cd06364
fix changeset description
swarnim02 5d91168
fix: correct changeset to patch level
swarnim02 79a6868
fix: update test structure and remove integration test
swarnim02 61c961f
fix(rsc): normalize double slashes in joinPaths function
swarnim02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "react-router": patch | ||
| --- | ||
|
|
||
| Fix RSC double slashes in manifest URLs | ||
|
|
||
| Normalize double slashes in getManifestUrl function to prevent ERR_NAME_NOT_RESOLVED errors when URLs contain double slashes like //en//test2/test | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -459,3 +459,4 @@ | |
| - zeromask1337 | ||
| - zheng-chuang | ||
| - zxTomw | ||
| - swarnim02 | ||
20 changes: 20 additions & 0 deletions
20
packages/react-router/__tests__/rsc-double-slashes-test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { joinPaths } from "../lib/router/utils"; | ||
|
|
||
| describe("joinPaths double slash normalization", () => { | ||
| it("normalizes double slashes in single path", () => { | ||
| expect(joinPaths(["//en//test2/test"])).toBe("/en/test2/test"); | ||
| expect(joinPaths(["/app//base/"])).toBe("/app/base/"); | ||
| expect(joinPaths(["///multiple///slashes"])).toBe("/multiple/slashes"); | ||
| }); | ||
|
|
||
| it("normalizes double slashes in multiple paths", () => { | ||
| expect(joinPaths(["//en//test1", "//fr//test2"])).toBe("/en/test1/fr/test2"); | ||
| expect(joinPaths(["path//with//double", "slashes//here"])).toBe("path/with/double/slashes/here"); | ||
| }); | ||
|
|
||
| it("preserves normal paths", () => { | ||
| expect(joinPaths(["/normal/path"])).toBe("/normal/path"); | ||
| expect(joinPaths(["path/without/leading/slash"])).toBe("path/without/leading/slash"); | ||
| expect(joinPaths([""])).toBe(""); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ import type { | |
| DataStrategyFunctionArgs, | ||
| RouterContextProvider, | ||
| } from "../router/utils"; | ||
| import { ErrorResponseImpl, createContext } from "../router/utils"; | ||
| import { ErrorResponseImpl, createContext, joinPaths } from "../router/utils"; | ||
| import type { | ||
| DecodedSingleFetchResults, | ||
| FetchAndDecodeFunction, | ||
|
|
@@ -972,16 +972,22 @@ function getManifestUrl(paths: string[]): URL | null { | |
| } | ||
|
|
||
| if (paths.length === 1) { | ||
| return new URL(`${paths[0]}.manifest`, window.location.origin); | ||
| // Normalize double slashes in the single path | ||
| const normalizedPath = joinPaths([paths[0]]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're not joining any paths here, I'd prefer to just see this manually done via a |
||
| return new URL(`${normalizedPath}.manifest`, window.location.origin); | ||
| } | ||
|
|
||
| const globalVar = window as WindowWithRouterGlobals; | ||
| let basename = (globalVar.__reactRouterDataRouter.basename ?? "").replace( | ||
| /^\/|\/$/g, | ||
| "", | ||
| ); | ||
| // Normalize double slashes in basename | ||
| basename = joinPaths([basename]); | ||
| let url = new URL(`${basename}/.manifest`, window.location.origin); | ||
| url.searchParams.set("paths", paths.sort().join(",")); | ||
| // Normalize double slashes in all paths before joining | ||
| const normalizedPaths = paths.map(path => joinPaths([path])); | ||
| url.searchParams.set("paths", normalizedPaths.sort().join(",")); | ||
|
|
||
| return url; | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is this change needed? The existing function already normalizes double slashes globally after the join