Skip to content

Commit 813497a

Browse files
authored
Drop support for Node 18 and installGlobals (#12171)
1 parent f294df8 commit 813497a

File tree

47 files changed

+100
-213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+100
-213
lines changed

.changeset/tidy-pens-help.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@react-router/express": major
3+
"@react-router/node": major
4+
"@react-router/dev": major
5+
"react-router": major
6+
---
7+
8+
Drop support for Node 18, update minimum Node vestion to 20
9+
10+
- Remove `installGlobals()` as this should no longer be necessary

.github/workflows/integration-full.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
uses: ./.github/workflows/shared-integration.yml
3535
with:
3636
os: "ubuntu-latest"
37-
node_version: "[18, 20]"
37+
node_version: "[20, 22]"
3838
browser: '["chromium", "firefox"]'
3939

4040
integration-windows:
@@ -43,7 +43,7 @@ jobs:
4343
uses: ./.github/workflows/shared-integration.yml
4444
with:
4545
os: "windows-latest"
46-
node_version: "[18, 20]"
46+
node_version: "[20, 22]"
4747
browser: '["msedge"]'
4848

4949
integration-macos:
@@ -52,5 +52,5 @@ jobs:
5252
uses: ./.github/workflows/shared-integration.yml
5353
with:
5454
os: "macos-latest"
55-
node_version: "[18, 20]"
55+
node_version: "[20, 22]"
5656
browser: '["webkit"]'

.github/workflows/integration-pr-ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ jobs:
3131
uses: ./.github/workflows/shared-integration.yml
3232
with:
3333
os: "ubuntu-latest"
34-
node_version: "[20]"
34+
node_version: "[22]"
3535
browser: '["chromium"]'

.github/workflows/integration-pr-windows-macos.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
uses: ./.github/workflows/shared-integration.yml
2222
with:
2323
os: "ubuntu-latest"
24-
node_version: "[20]"
24+
node_version: "[22]"
2525
browser: '["firefox"]'
2626

2727
integration-msedge:
@@ -30,7 +30,7 @@ jobs:
3030
uses: ./.github/workflows/shared-integration.yml
3131
with:
3232
os: "windows-latest"
33-
node_version: "[20]"
33+
node_version: "[22]"
3434
browser: '["msedge"]'
3535

3636
integration-webkit:
@@ -39,5 +39,5 @@ jobs:
3939
uses: ./.github/workflows/shared-integration.yml
4040
with:
4141
os: "macos-latest"
42-
node_version: "[20]"
42+
node_version: "[22]"
4343
browser: '["webkit"]'

.github/workflows/shared-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
node_version:
1010
required: true
1111
# this is limited to string | boolean | number (https://github.saobby.my.eu.orgmunity/t/can-action-inputs-be-arrays/16457)
12-
# but we want to pass an array (node_version: "[18, 20]"),
12+
# but we want to pass an array (node_version: "[20, 22]"),
1313
# so we'll need to manually stringify it for now
1414
type: string
1515
browser:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ jobs:
2626
fail-fast: false
2727
matrix:
2828
node:
29-
- 18
3029
- 20
30+
- 22
3131

3232
runs-on: ubuntu-latest
3333

docs/deploying/custom-node.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,41 @@ title: Custom Node.js
77
<docs-warning>
88
This document is a work in progress. There's not much to see here (yet).
99
</docs-warning>
10+
11+
## Polyfilling `fetch`
12+
13+
React Router officially supports Active and Maintenance[^1] [Node LTS veleases][node-releases] at any given point in time. Dropping support for End of Life Node versions may be done in a React Router Minor release.
14+
15+
[^1]: Based on timing, React Router may drop support for a Node Maintenance LTS version shortly before it goes end-of-life if it better aligns with a React Router Major SemVer release.
16+
17+
At the time React Router v7 was released, all versions had a usable `fetch` implementation so there is generally no need to polyfill any `fetch` APIs so long as you're on Node 22 or one of the later Node 20 releases.
18+
19+
- Node 22 (Active LTS) has a stable [`fetch`][node-22-fetch] implementation
20+
- Node 20 (Maintenance LTS) has an experimental (but suitable from our testing) [`fetch`][node-20-fetch] implementation
21+
22+
If you do find that you need to polyfill anything, you can do so directly from the [undici] package which node uses internally.
23+
24+
```ts
25+
import {
26+
fetch as nodeFetch,
27+
File as NodeFile,
28+
FormData as NodeFormData,
29+
Headers as NodeHeaders,
30+
Request as NodeRequest,
31+
Response as NodeResponse,
32+
} from "undici";
33+
34+
export function polyfillFetch() {
35+
global.File = NodeFile;
36+
global.Headers = NodeHeaders;
37+
global.Request = NodeRequest;
38+
global.Response = NodeResponse;
39+
global.fetch = nodeFetch;
40+
global.FormData = NodeFormData;
41+
}
42+
```
43+
44+
[node-releases]: https://nodejs.org/en/about/previous-releases
45+
[node-20-fetch]: https://nodejs.org/docs/latest-v20.x/api/globals.html#fetch
46+
[node-22-fetch]: https://nodejs.org/docs/latest-v22.x/api/globals.html#fetch
47+
[undici]: https://github.com/nodejs/undici

integration/helpers/create-fixture.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
UNSAFE_decodeViaTurboStream as decodeViaTurboStream,
1616
} from "react-router";
1717
import { createRequestHandler as createExpressHandler } from "@react-router/express";
18-
import { installGlobals } from "@react-router/node";
1918

2019
import { viteConfig } from "./vite.js";
2120

@@ -43,8 +42,6 @@ export function json(value: JsonObject) {
4342
}
4443

4544
export async function createFixture(init: FixtureInit, mode?: ServerMode) {
46-
installGlobals();
47-
4845
let projectDir = await createFixtureProject(init, mode);
4946
let buildPath = url.pathToFileURL(
5047
path.join(projectDir, "build/server/index.js")

integration/helpers/node-template/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434
"typescript": "^5.1.0"
3535
},
3636
"engines": {
37-
"node": ">=18.0.0"
37+
"node": ">=20.0.0"
3838
}
3939
}

integration/helpers/vite-cloudflare-template/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
"wrangler": "^3.28.2"
3131
},
3232
"engines": {
33-
"node": ">=18.0.0"
33+
"node": ">=20.0.0"
3434
}
3535
}

0 commit comments

Comments
 (0)