@netlify/vite-plugin-react-router 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.0.1](https://github.com/netlify/remix-compute/compare/vite-plugin-react-router-v2.0.0...vite-plugin-react-router-v2.0.1) (2025-10-20)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * populate value for Netlify React Router context in dev ([#550](https://github.com/netlify/remix-compute/issues/550)) ([8d2c9fd](https://github.com/netlify/remix-compute/commit/8d2c9fd21090ca063d99a9e7094393932d870801))
9
+
3
10
  ## [2.0.0](https://github.com/netlify/remix-compute/compare/vite-plugin-react-router-v1.0.1...vite-plugin-react-router-v2.0.0) (2025-10-16)
4
11
 
5
12
  ### ⚠ BREAKING CHANGES
package/README.md CHANGED
@@ -3,27 +3,37 @@
3
3
  The React Router Adapter for Netlify allows you to deploy your [React Router](https://reactrouter.com) app to
4
4
  [Netlify Functions](https://docs.netlify.com/functions/overview/).
5
5
 
6
- To deploy a React Router 7+ site to Netlify, install this package:
7
-
8
6
  ## How to use
9
7
 
8
+ To deploy a React Router 7+ site to Netlify, install this package:
9
+
10
10
  ```sh
11
11
  npm install --save-dev @netlify/vite-plugin-react-router
12
12
  ```
13
13
 
14
+ It's also recommended (but not required) to use the
15
+ [Netlify Vite plugin](https://www.npmjs.com/package/@netlify/vite-plugin), which provides full Netlify platform
16
+ emulation directly in your local dev server:
17
+
18
+ ```sh
19
+ npm install --save-dev @netlify/vite-plugin
20
+ ```
21
+
14
22
  and include the Netlify plugin in your `vite.config.ts`:
15
23
 
16
24
  ```typescript
17
25
  import { reactRouter } from '@react-router/dev/vite'
18
26
  import { defineConfig } from 'vite'
19
27
  import tsconfigPaths from 'vite-tsconfig-paths'
20
- import netlifyPlugin from '@netlify/vite-plugin-react-router' // <- add this
28
+ import netlifyReactRouter from '@netlify/vite-plugin-react-router' // <- add this
29
+ import netlify from '@netlify/vite-plugin' // <- add this (optional)
21
30
 
22
31
  export default defineConfig({
23
32
  plugins: [
24
33
  reactRouter(),
25
34
  tsconfigPaths(),
26
- netlifyPlugin(), // <- add this
35
+ netlifyReactRouter(), // <- add this
36
+ netlify(), // <- add this (optional)
27
37
  ],
28
38
  })
29
39
  ```
@@ -76,6 +86,12 @@ export default function Example() {
76
86
  }
77
87
  ```
78
88
 
89
+ > [!IMPORTANT]
90
+ >
91
+ > Note that in local development, `netlifyRouterContext` requires Netlify platform emulation, which is provided
92
+ > seamlessly by [`@netlify/vite-plugin`](https://www.npmjs.com/package/@netlify/vite-plugin) (or Netlify CLI - up to
93
+ > you).
94
+
79
95
  ### Middleware context
80
96
 
81
97
  React Router introduced a stable middleware feature in 7.9.0.
@@ -103,3 +119,9 @@ export default function Home() {
103
119
  return <h1>Hello world</h1>
104
120
  }
105
121
  ```
122
+
123
+ > [!IMPORTANT]
124
+ >
125
+ > Note that in local development, `netlifyRouterContext` requires Netlify platform emulation, which is provided
126
+ > seamlessly by [`@netlify/vite-plugin`](https://www.npmjs.com/package/@netlify/vite-plugin) (or Netlify CLI - up to
127
+ > you).
package/dist/index.d.mts CHANGED
@@ -28,7 +28,7 @@ type RequestHandler = (request: Request, context: Context) => Promise<Response>;
28
28
  *
29
29
  * @example context.get(netlifyRouterContext).geo?.country?.name
30
30
  */
31
- declare const netlifyRouterContext: react_router.RouterContext<Context>;
31
+ declare const netlifyRouterContext: react_router.RouterContext<Partial<Context>>;
32
32
  /**
33
33
  * Given a build and a callback to get the base loader context, this returns
34
34
  * a Netlify Function handler (https://docs.netlify.com/functions/overview/) which renders the
package/dist/index.d.ts CHANGED
@@ -28,7 +28,7 @@ type RequestHandler = (request: Request, context: Context) => Promise<Response>;
28
28
  *
29
29
  * @example context.get(netlifyRouterContext).geo?.country?.name
30
30
  */
31
- declare const netlifyRouterContext: react_router.RouterContext<Context>;
31
+ declare const netlifyRouterContext: react_router.RouterContext<Partial<Context>>;
32
32
  /**
33
33
  * Given a build and a callback to get the base loader context, this returns
34
34
  * a Netlify Function handler (https://docs.netlify.com/functions/overview/) which renders the
package/dist/index.js CHANGED
@@ -28,7 +28,37 @@ module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/server.ts
30
30
  var import_react_router = require("react-router");
31
- var netlifyRouterContext = (0, import_react_router.createContext)();
31
+ var netlifyRouterContext = (
32
+ // We must use a singleton because Remix contexts rely on referential equality.
33
+ // We can't hook into the request lifecycle in dev mode, so we use a Proxy to always read from the
34
+ // current `Netlify.context` value, which is always contextual to the in-flight request.
35
+ (0, import_react_router.createContext)(
36
+ new Proxy(
37
+ // Can't reference `Netlify.context` here because it isn't set outside of a request lifecycle
38
+ {},
39
+ {
40
+ get(_target, prop, receiver) {
41
+ return Reflect.get(Netlify.context ?? {}, prop, receiver);
42
+ },
43
+ set(_target, prop, value, receiver) {
44
+ return Reflect.set(Netlify.context ?? {}, prop, value, receiver);
45
+ },
46
+ has(_target, prop) {
47
+ return Reflect.has(Netlify.context ?? {}, prop);
48
+ },
49
+ deleteProperty(_target, prop) {
50
+ return Reflect.deleteProperty(Netlify.context ?? {}, prop);
51
+ },
52
+ ownKeys(_target) {
53
+ return Reflect.ownKeys(Netlify.context ?? {});
54
+ },
55
+ getOwnPropertyDescriptor(_target, prop) {
56
+ return Reflect.getOwnPropertyDescriptor(Netlify.context ?? {}, prop);
57
+ }
58
+ }
59
+ )
60
+ )
61
+ );
32
62
  function createRequestHandler({
33
63
  build,
34
64
  mode,
@@ -64,7 +94,7 @@ var import_posix = require("path/posix");
64
94
 
65
95
  // package.json
66
96
  var name = "@netlify/vite-plugin-react-router";
67
- var version = "2.0.0";
97
+ var version = "2.0.1";
68
98
 
69
99
  // src/plugin.ts
70
100
  var NETLIFY_FUNCTIONS_DIR = ".netlify/v1/functions";
package/dist/index.mjs CHANGED
@@ -4,7 +4,37 @@ import {
4
4
  RouterContextProvider,
5
5
  createRequestHandler as createReactRouterRequestHandler
6
6
  } from "react-router";
7
- var netlifyRouterContext = createContext();
7
+ var netlifyRouterContext = (
8
+ // We must use a singleton because Remix contexts rely on referential equality.
9
+ // We can't hook into the request lifecycle in dev mode, so we use a Proxy to always read from the
10
+ // current `Netlify.context` value, which is always contextual to the in-flight request.
11
+ createContext(
12
+ new Proxy(
13
+ // Can't reference `Netlify.context` here because it isn't set outside of a request lifecycle
14
+ {},
15
+ {
16
+ get(_target, prop, receiver) {
17
+ return Reflect.get(Netlify.context ?? {}, prop, receiver);
18
+ },
19
+ set(_target, prop, value, receiver) {
20
+ return Reflect.set(Netlify.context ?? {}, prop, value, receiver);
21
+ },
22
+ has(_target, prop) {
23
+ return Reflect.has(Netlify.context ?? {}, prop);
24
+ },
25
+ deleteProperty(_target, prop) {
26
+ return Reflect.deleteProperty(Netlify.context ?? {}, prop);
27
+ },
28
+ ownKeys(_target) {
29
+ return Reflect.ownKeys(Netlify.context ?? {});
30
+ },
31
+ getOwnPropertyDescriptor(_target, prop) {
32
+ return Reflect.getOwnPropertyDescriptor(Netlify.context ?? {}, prop);
33
+ }
34
+ }
35
+ )
36
+ )
37
+ );
8
38
  function createRequestHandler({
9
39
  build,
10
40
  mode,
@@ -40,7 +70,7 @@ import { sep as posixSep } from "node:path/posix";
40
70
 
41
71
  // package.json
42
72
  var name = "@netlify/vite-plugin-react-router";
43
- var version = "2.0.0";
73
+ var version = "2.0.1";
44
74
 
45
75
  // src/plugin.ts
46
76
  var NETLIFY_FUNCTIONS_DIR = ".netlify/v1/functions";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/vite-plugin-react-router",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "React Router 7+ Vite plugin for Netlify",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",