You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: static generated RSC x-component and response type selection (#99)
This PR fixes issues around static generated RSC x-component files and
how response type selection works to send an RSC payload. The response
type selection needs to be on par with the static generation to maintain
the same solution for both static and dynamic rendering.
Changes request payload to select RSC rendering. Instead of using HTTP
headers, the framework now uses an URL pathname suffix, including outlet
name and remote or standard RSC rendering and static generation uses the
same format in filenames. This fixes#95.
Adds build options to enable compression (GZip and Brotli) and opt-out
of static RSC rendering, see more about this in the updated docs.
Adds static export option to render a single outlet. This is mainly to
keep consistency with the URL format right now, but might be a useful
feature for SSG.
Updates the deployment Adapter API to not copy compressed files by
default, but copy static RSC files and also the Vercel adapter to add
the necessary
`Content-Type` header for static `.x-component` files. This fixes#94.
Removes the `standalone` route option and mode as it was not really
useful and there are other ways to achieve the same functionality.
Copy file name to clipboardExpand all lines: docs/src/pages/en/(pages)/framework/cli.mdx
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,6 +98,9 @@ You can disable client build if you only want to build the server part of your a
98
98
**export:** Static export. Default is `false`.
99
99
You can export your app as static HTML pages. You can define the routes to export in your `react-server.config.mjs` file. See more details at [Static generation](/router/static).
100
100
101
+
**compression:** Enable compression. Default is `false`.
102
+
You can enable compression if you want to compress your static build. Compression is not enabled by default for static builds. Gzip and Brotli compression is used when compression is enabled. The production mode server serves these compressed files by default when the compressed static files are present.
103
+
101
104
**deploy:** Deploy using adapter. Default is `false`.
102
105
If you use an adapter in your `react-server.config.mjs` file, the adapter will pre-build your app for deployment and when you use this argument, the adapter will also deploy your app at the end of the build process.
Copy file name to clipboardExpand all lines: docs/src/pages/en/(pages)/router/server-routing.mdx
-28Lines changed: 0 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -178,34 +178,6 @@ export default function App() {
178
178
}
179
179
```
180
180
181
-
<Linkname="route-rendering-in-standalone-mode">
182
-
## Route rendering in standalone-mode
183
-
</Link>
184
-
185
-
If you want a route to render only it's children when using client-side navigation, you can set the value of the `standalone` prop on the `Route` component to be `false`. This will prevent the route from using it's `render` function when the path matches the route. Upon client-side navigation or refreshing, the route will only render it's children.
@@ -52,7 +52,7 @@ You can use static JSON data for your static pages by creating a file with the `
52
52
53
53
For example, if you have a page at `/users/:id` you can create a file at `/users/[id].static.json` with the following content:
54
54
55
-
```json
55
+
```json filename="users/[id].static.json"
56
56
[{ "id": 1 }, { "id": 2 }, { "id": 3 }]
57
57
```
58
58
@@ -64,7 +64,7 @@ For example, if you have a page at `/users/:id` you can create a file at `/users
64
64
65
65
You can override all static paths by defining an `export()` function in your `@lazarv/react-server` configuration file. This function will be called with an array of all static paths and you can return a new array of paths to override the default static paths. In this example, we remove the `/en` prefix from all static paths.
66
66
67
-
```js
67
+
```js filename="react-server.config.mjs"
68
68
exportdefault {
69
69
export(paths) {
70
70
returnpaths.map(({ path }) => ({
@@ -76,7 +76,7 @@ export default {
76
76
77
77
You can also use this function to add new static paths or remove some paths.
78
78
79
-
```js
79
+
```js filename="react-server.config.mjs"
80
80
exportdefault {
81
81
export(paths) {
82
82
return [
@@ -87,7 +87,7 @@ export default {
87
87
};
88
88
```
89
89
90
-
```js
90
+
```js filename="react-server.config.mjs"
91
91
exportdefault {
92
92
export(paths) {
93
93
returnpaths.filter(({ path }) => path !=="/en");
@@ -101,7 +101,7 @@ export default {
101
101
102
102
You can also export API routes as static routes. To do this, you can define your static path as an object with the `path`, `filename`, `method` and `headers` properties, where `path` is the route path, `filename` is the filename for the static file, `method` is the HTTP method for the request and `headers` is an object with the headers for the request. `method` and `headers` are optional.
103
103
104
-
```js
104
+
```js filename="react-server.config.mjs"
105
105
exportdefault {
106
106
export() {
107
107
return [
@@ -124,7 +124,7 @@ export default {
124
124
125
125
You can also export micro-frontend routes as static. To do this, you can define your static path as an object with the `path` and `remote` properties, where `path` is the route path and `remote` is a flag to indicate that the route is a micro-frontend route and the remote response payload needs to be generated at build time. By using static export for micro-frontends, you can improve the performance of your application by pre-rendering the micro-frontend content at build time.
126
126
127
-
```js
127
+
```js filename="react-server.config.mjs"
128
128
exportdefault {
129
129
export() {
130
130
return [
@@ -135,4 +135,32 @@ export default {
135
135
];
136
136
},
137
137
};
138
-
```
138
+
```
139
+
140
+
<Linkname="static-export-outlets">
141
+
## Static export outlets
142
+
</Link>
143
+
144
+
You can also export outlets as static. To do this, you can define your static path as an object with the `path` and `outlet` properties, where `path` is the route path and `outlet` is the name of the outlet. By using static export for outlets, you can improve the performance of your application by pre-rendering the outlet content at build time. Exported outlets will be rendered as RSC components. Client-side navigation to an exported outlet will use the static outlet content instead of making a request to the server.
145
+
146
+
```js filename="react-server.config.mjs"
147
+
exportdefault {
148
+
export() {
149
+
return [{ path:"/photos/1", outlet:"modal" }];
150
+
},
151
+
};
152
+
```
153
+
154
+
<Linkname="disable-static-export-for-rsc-routes">
155
+
## Disable static export for RSC routes
156
+
</Link>
157
+
158
+
You can disable static export for RSC routes by setting the `rsc` property to `false`. This is useful if you have a page that is an RSC route but you don't want to pre-render it at build time or you don't plan to use the RSC payload for that route. This will prevent the RSC payload from being generated at build time and the route will be rendered only as a regular HTML page to reduce the deployment size.
0 commit comments