@quilted/quilt 0.5.130 → 0.5.132
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 +12 -0
- package/build/cjs/server/index.cjs +17 -2
- package/build/cjs/server/request-router.cjs +192 -41
- package/build/cjs/static/index.cjs +47 -29
- package/build/esm/server/index.mjs +2 -3
- package/build/esm/server/request-router.mjs +192 -42
- package/build/esm/static/index.mjs +48 -30
- package/build/esnext/server/index.esnext +2 -3
- package/build/esnext/server/request-router.esnext +192 -42
- package/build/esnext/static/index.esnext +48 -30
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/server/index.d.ts +3 -4
- package/build/typescript/server/index.d.ts.map +1 -1
- package/build/typescript/server/request-router.d.ts +21 -12
- package/build/typescript/server/request-router.d.ts.map +1 -1
- package/build/typescript/static/index.d.ts +1 -1
- package/build/typescript/static/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/source/server/index.ts +14 -5
- package/source/server/request-router.tsx +273 -72
- package/source/static/index.tsx +62 -28
- package/build/cjs/server/render.cjs +0 -41
- package/build/esm/server/render.mjs +0 -39
- package/build/esnext/server/render.esnext +0 -39
- package/source/server/render.tsx +0 -50
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { styleAssetAttributes, scriptAssetAttributes, styleAssetPreloadAttributes, scriptAssetPreloadAttributes } from '@quilted/async/server';
|
|
1
2
|
import { renderHtmlToString, Html } from '@quilted/react-html/server';
|
|
2
3
|
import { StaticRenderer, StaticRendererContext } from '@quilted/react-router/static';
|
|
3
4
|
import { renderApp } from './render.esnext';
|
|
4
|
-
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
6
|
|
|
6
7
|
const BASE_URL = 'http://localhost:3000';
|
|
7
8
|
async function renderStatic(App, {
|
|
@@ -173,30 +174,20 @@ async function renderStatic(App, {
|
|
|
173
174
|
const usedAssets = asyncAssets.used({
|
|
174
175
|
timing: 'load'
|
|
175
176
|
});
|
|
176
|
-
const [
|
|
177
|
+
const [moduleAssets, modulePreload, nomoduleAssets] = await Promise.all([assets.assets({
|
|
177
178
|
async: usedAssets,
|
|
178
|
-
|
|
179
|
-
modules: true
|
|
180
|
-
}
|
|
181
|
-
}), assets.scripts({
|
|
182
|
-
async: usedAssets,
|
|
183
|
-
options: {
|
|
179
|
+
context: {
|
|
184
180
|
modules: true
|
|
185
181
|
}
|
|
186
182
|
}), assets.asyncAssets(asyncAssets.used({
|
|
187
183
|
timing: 'preload'
|
|
188
184
|
}), {
|
|
189
|
-
|
|
185
|
+
context: {
|
|
190
186
|
modules: true
|
|
191
187
|
}
|
|
192
|
-
}), assets.
|
|
193
|
-
async: usedAssets,
|
|
194
|
-
options: {
|
|
195
|
-
modules: false
|
|
196
|
-
}
|
|
197
|
-
}), assets.scripts({
|
|
188
|
+
}), assets.assets({
|
|
198
189
|
async: usedAssets,
|
|
199
|
-
|
|
190
|
+
context: {
|
|
200
191
|
modules: false
|
|
201
192
|
}
|
|
202
193
|
})]);
|
|
@@ -204,22 +195,49 @@ async function renderStatic(App, {
|
|
|
204
195
|
// We don’t want to load styles from both bundles, so we only use module styles,
|
|
205
196
|
// since modules are intended to be the default and CSS (usually) doesn’t
|
|
206
197
|
// have features that meaningfully break older user agents.
|
|
207
|
-
const styles =
|
|
208
|
-
|
|
209
|
-
// If there are nomodule scripts, we can’t really do preloading, because we can’t
|
|
210
|
-
// prevent the nomodule scripts from being preloaded in module browsers. If there
|
|
211
|
-
// are only module scripts, we can preload those.
|
|
212
|
-
const preload = nomoduleScripts.length > 0 ? [] : modulePreload;
|
|
213
|
-
const scripts = [...moduleScripts, ...nomoduleScripts.map(script => ({
|
|
214
|
-
...script,
|
|
215
|
-
nomodule: true
|
|
216
|
-
}))];
|
|
198
|
+
const styles = moduleAssets.styles.length > 0 ? moduleAssets.styles : nomoduleAssets.styles;
|
|
217
199
|
const minifiedHtml = renderHtmlToString( /*#__PURE__*/jsx(Html, {
|
|
218
|
-
url: url,
|
|
219
200
|
manager: htmlManager,
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
201
|
+
headEndContent: /*#__PURE__*/jsxs(Fragment, {
|
|
202
|
+
children: [[...styles].map(style => {
|
|
203
|
+
const attributes = styleAssetAttributes(style, {
|
|
204
|
+
baseUrl: url
|
|
205
|
+
});
|
|
206
|
+
return /*#__PURE__*/jsx("link", {
|
|
207
|
+
...attributes
|
|
208
|
+
}, style.source);
|
|
209
|
+
}), [...moduleAssets.scripts].map(script => {
|
|
210
|
+
const attributes = scriptAssetAttributes(script, {
|
|
211
|
+
baseUrl: url
|
|
212
|
+
});
|
|
213
|
+
return /*#__PURE__*/jsx("script", {
|
|
214
|
+
...attributes
|
|
215
|
+
}, script.source);
|
|
216
|
+
}), [...nomoduleAssets.scripts].map(script => {
|
|
217
|
+
const attributes = scriptAssetAttributes(script, {
|
|
218
|
+
baseUrl: url
|
|
219
|
+
});
|
|
220
|
+
return /*#__PURE__*/jsx("script", {
|
|
221
|
+
...attributes,
|
|
222
|
+
// @ts-expect-error Rendering to HTML, so using the lowercase name
|
|
223
|
+
nomodule: moduleAssets.scripts.length > 0 ? true : undefined
|
|
224
|
+
}, script.source);
|
|
225
|
+
}), [...modulePreload.styles].map(style => {
|
|
226
|
+
const attributes = styleAssetPreloadAttributes(style, {
|
|
227
|
+
baseUrl: url
|
|
228
|
+
});
|
|
229
|
+
return /*#__PURE__*/jsx("link", {
|
|
230
|
+
...attributes
|
|
231
|
+
}, style.source);
|
|
232
|
+
}), [...modulePreload.scripts].map(script => {
|
|
233
|
+
const attributes = scriptAssetPreloadAttributes(script, {
|
|
234
|
+
baseUrl: url
|
|
235
|
+
});
|
|
236
|
+
return /*#__PURE__*/jsx("link", {
|
|
237
|
+
...attributes
|
|
238
|
+
}, script.source);
|
|
239
|
+
})]
|
|
240
|
+
}),
|
|
223
241
|
children: markup
|
|
224
242
|
}));
|
|
225
243
|
const html = prettify ? await prettifyHtml(minifiedHtml) : minifiedHtml;
|