-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hotfix: absolute URLs on server router (#10112)
Co-authored-by: Matt Brophy <[email protected]>
- Loading branch information
1 parent
3c6fb46
commit 8975de9
Showing
6 changed files
with
70 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"react-router-dom": patch | ||
--- | ||
|
||
Fix SSR of absolute Link urls |
This file contains 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 |
---|---|---|
|
@@ -163,6 +163,7 @@ | |
- tanayv | ||
- theostavrides | ||
- thisiskartik | ||
- thomasverleye | ||
- ThornWu | ||
- timdorr | ||
- TkDodo | ||
|
This file contains 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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
|
||
import * as React from "react"; | ||
import * as ReactDOMServer from "react-dom/server"; | ||
import type { StaticHandlerContext } from "@remix-run/router"; | ||
|
@@ -642,6 +646,44 @@ describe("A <StaticRouterProvider>", () => { | |
`); | ||
}); | ||
|
||
it("renders absolute links correctly", async () => { | ||
let routes = [ | ||
{ | ||
path: "/", | ||
element: ( | ||
<> | ||
<Link to="/the/path">relative path</Link> | ||
<Link to="http://localhost/the/path">absolute same-origin url</Link> | ||
<Link to="https://remix.run">absolute different-origin url</Link> | ||
<Link to="mailto:[email protected]">absolute mailto: url</Link> | ||
</> | ||
), | ||
}, | ||
]; | ||
let { query } = createStaticHandler(routes); | ||
|
||
let context = (await query( | ||
new Request("http://localhost/", { | ||
signal: new AbortController().signal, | ||
}) | ||
)) as StaticHandlerContext; | ||
|
||
let html = ReactDOMServer.renderToStaticMarkup( | ||
<React.StrictMode> | ||
<StaticRouterProvider | ||
router={createStaticRouter(routes, context)} | ||
context={context} | ||
/> | ||
</React.StrictMode> | ||
); | ||
expect(html).toMatch( | ||
'<a href="/the/path">relative path</a>' + | ||
'<a href="http://localhost/the/path">absolute same-origin url</a>' + | ||
'<a href="https://remix.run">absolute different-origin url</a>' + | ||
'<a href="mailto:[email protected]">absolute mailto: url</a>' | ||
); | ||
}); | ||
|
||
describe("boundary tracking", () => { | ||
it("tracks the deepest boundary during render", async () => { | ||
let routes = [ | ||
|
5 changes: 3 additions & 2 deletions
5
packages/react-router-dom/__tests__/polyfills/SubmitEvent.submitter.ts
This file contains 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 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 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