@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.
@@ -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 [moduleStyles, moduleScripts, modulePreload, nomoduleStyles, nomoduleScripts] = await Promise.all([assets.styles({
177
+ const [moduleAssets, modulePreload, nomoduleAssets] = await Promise.all([assets.assets({
177
178
  async: usedAssets,
178
- options: {
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
- options: {
185
+ context: {
190
186
  modules: true
191
187
  }
192
- }), assets.styles({
193
- async: usedAssets,
194
- options: {
195
- modules: false
196
- }
197
- }), assets.scripts({
188
+ }), assets.assets({
198
189
  async: usedAssets,
199
- options: {
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 = moduleStyles.length > 0 ? moduleStyles : nomoduleStyles;
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
- styles: styles,
221
- scripts: scripts,
222
- preloadAssets: preload,
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;