@quilted/quilt 0.5.104 → 0.5.107

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/build/cjs/AppContext.cjs +2 -3
  3. package/build/cjs/env.cjs +1 -1
  4. package/build/cjs/server/ServerContext.cjs +7 -8
  5. package/build/cjs/server/http-handler.cjs +188 -70
  6. package/build/cjs/server/index.cjs +16 -0
  7. package/build/cjs/server/render.cjs +75 -30
  8. package/build/cjs/static/StaticContext.cjs +7 -8
  9. package/build/cjs/static/index.cjs +589 -244
  10. package/build/cjs/static/render.cjs +75 -30
  11. package/build/esm/AppContext.mjs +2 -3
  12. package/build/esm/env.mjs +1 -1
  13. package/build/esm/server/ServerContext.mjs +7 -8
  14. package/build/esm/server/http-handler.mjs +181 -71
  15. package/build/esm/server/index.mjs +1 -1
  16. package/build/esm/server/render.mjs +68 -30
  17. package/build/esm/static/StaticContext.mjs +7 -8
  18. package/build/esm/static/index.mjs +585 -248
  19. package/build/esm/static/render.mjs +68 -30
  20. package/build/esnext/server/http-handler.esnext +1 -1
  21. package/build/esnext/server/index.esnext +1 -1
  22. package/build/tsconfig.tsbuildinfo +1 -1
  23. package/build/typescript/server/http-handler.d.ts +2 -2
  24. package/build/typescript/server/http-handler.d.ts.map +1 -1
  25. package/build/typescript/server/index.d.ts +2 -2
  26. package/build/typescript/server/index.d.ts.map +1 -1
  27. package/package.json +41 -23
  28. package/quilt.project.ts +3 -38
  29. package/source/server/http-handler.tsx +1 -2
  30. package/source/server/index.ts +16 -5
  31. package/tsconfig.json +1 -1
  32. package/build/typescript/App.d.ts +0 -15
  33. package/build/typescript/App.d.ts.map +0 -1
  34. package/build/typescript/magic/asset-loader.d.ts +0 -6
  35. package/build/typescript/magic/asset-loader.d.ts.map +0 -1
  36. package/build/typescript/react/server.d.ts +0 -2
  37. package/build/typescript/react/server.d.ts.map +0 -1
  38. package/build/typescript/react/test-utils.d.ts +0 -2
  39. package/build/typescript/react/test-utils.d.ts.map +0 -1
  40. package/build/typescript/workers/index.d.ts +0 -2
  41. package/build/typescript/workers/index.d.ts.map +0 -1
  42. package/build/typescript/workers/worker.d.ts +0 -2
  43. package/build/typescript/workers/worker.d.ts.map +0 -1
@@ -1,270 +1,607 @@
1
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
4
+ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
5
+ import _regeneratorRuntime from '@babel/runtime/regenerator';
1
6
  import { render, Html } from '@quilted/react-html/server';
2
7
  import { StaticRenderer, StaticRendererContext } from '@quilted/react-router/static';
3
8
  import { renderApp } from './render.mjs';
4
9
  import { jsx } from 'react/jsx-runtime';
5
10
 
6
- const BASE_URL = 'http://localhost:3000';
7
- async function renderStatic(App, {
8
- assets,
9
- routes: startingRoutes,
10
- onRender,
11
- crawl = true,
12
- baseUrl = BASE_URL,
13
- prettify = true
14
- }) {
15
- const routesToHandle = startingRoutes.map(route => ({
16
- route: removePostfixSlash(new URL(route, baseUrl).pathname),
17
- fallback: false
18
- }));
19
- const seenRoutes = [...routesToHandle];
20
- const seenRouteIds = new Set(seenRoutes.map(({
21
- route
22
- }) => route));
23
- let renderableRoute;
24
-
25
- while (renderableRoute = routesToHandle.shift()) {
26
- const {
27
- route,
28
- fallback
29
- } = renderableRoute;
30
- const url = new URL(route, baseUrl);
31
- const {
32
- html,
33
- http,
34
- routes
35
- } = await renderUrl(url, {
36
- fallback
37
- });
38
-
39
- if (crawl) {
40
- for (const {
41
- routes: routeDefinitions,
42
- fallback = false,
43
- consumedPath,
44
- prefix
45
- } of routes) {
46
- const basePathname = joinPath(prefix, consumedPath);
47
- const baseId = basePathname === '/' ? basePathname : `__QUILT_BASE_${basePathname}__`;
48
-
49
- for (const routeDefinition of routeDefinitions) {
50
- await recordRouteDefinition(routeDefinition, {
51
- baseId,
52
- basePathname,
53
- addFallbacks: fallback
54
- });
55
- }
11
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
56
12
 
57
- if (fallback && routeDefinitions[routeDefinitions.length - 1]?.match != null) {
58
- await recordRouteDefinition({}, {
59
- baseId,
60
- basePathname,
61
- addFallbacks: fallback
62
- });
63
- }
64
- }
65
- }
66
-
67
- await onRender({
68
- route,
69
- content: html,
70
- http,
71
- fallback,
72
- hasChildren: !fallback && seenRoutes.some(otherRoute => otherRoute.route.startsWith(`${route}/`))
73
- });
74
- }
13
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
75
14
 
76
- async function recordRouteDefinition({
77
- match,
78
- children,
79
- renderStatic
80
- }, {
81
- basePathname,
82
- baseId,
83
- addFallbacks
84
- }) {
85
- if (renderStatic === false) return;
86
- let routeId;
87
- const hasChildren = children && children.length > 0;
88
- const hasManualMatches = typeof renderStatic === 'function' && typeof match !== 'string';
89
- const matchedRoutes = [];
90
-
91
- if (typeof match === 'string') {
92
- routeId = joinPath(baseId, match);
93
- matchedRoutes.push({
94
- id: routeId,
95
- route: joinPath(basePathname, match),
96
- fallback: false
97
- });
98
- } else if (typeof match === 'function') {
99
- routeId = joinPath(baseId, `__QUILT_FUNCTION_ROUTE_${match.toString()}__`);
100
- } else if (match instanceof RegExp) {
101
- routeId = joinPath(`__QUILT_REGEX_ROUTE_${match.source}__`);
102
- } else {
103
- routeId = joinPath(baseId, '__QUILT_FALLBACK_ROUTE__');
104
-
105
- if (!hasManualMatches) {
106
- matchedRoutes.push({
107
- id: routeId,
108
- route: basePathname,
109
- fallback: true
110
- });
111
- }
112
- }
113
-
114
- if (seenRouteIds.has(routeId)) return;
115
- seenRouteIds.add(routeId);
116
-
117
- if (typeof renderStatic === 'function' && typeof match !== 'string') {
118
- const matchedRouteParts = await renderStatic();
119
-
120
- for (const routePart of matchedRouteParts) {
121
- const id = joinPath(baseId, `__QUILT_MATCH_${routePart}__`);
122
- seenRouteIds.add(id);
123
- matchedRoutes.push({
124
- id,
125
- route: joinPath(basePathname, routePart),
126
- fallback: false
127
- });
128
- }
129
- }
130
-
131
- if (hasChildren) {
132
- for (const {
133
- id,
134
- route
135
- } of matchedRoutes) {
136
- for (const child of children) {
137
- await recordRouteDefinition(child, {
138
- addFallbacks,
139
- basePathname: route,
140
- baseId: id
141
- });
142
- }
15
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
16
+
17
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
18
+
19
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
20
+ var BASE_URL = 'http://localhost:3000';
21
+ function renderStatic(_x, _x2) {
22
+ return _renderStatic.apply(this, arguments);
23
+ }
24
+
25
+ function _renderStatic() {
26
+ _renderStatic = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(App, _ref) {
27
+ var assets, startingRoutes, onRender, _ref$crawl, crawl, _ref$baseUrl, baseUrl, _ref$prettify, prettify, routesToHandle, seenRoutes, seenRouteIds, renderableRoute, _loop, recordRouteDefinition, _recordRouteDefinition, renderUrl, _renderUrl;
28
+
29
+ return _regeneratorRuntime.wrap(function _callee3$(_context4) {
30
+ while (1) {
31
+ switch (_context4.prev = _context4.next) {
32
+ case 0:
33
+ _renderUrl = function _renderUrl3() {
34
+ _renderUrl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(url) {
35
+ var _ref6,
36
+ _ref6$fallback,
37
+ fallback,
38
+ routeRecorder,
39
+ _yield$renderApp,
40
+ http,
41
+ htmlManager,
42
+ markup,
43
+ asyncAssets,
44
+ usedAssets,
45
+ _yield$Promise$all,
46
+ _yield$Promise$all2,
47
+ moduleStyles,
48
+ moduleScripts,
49
+ modulePreload,
50
+ nomoduleStyles,
51
+ nomoduleScripts,
52
+ styles,
53
+ preload,
54
+ scripts,
55
+ minifiedHtml,
56
+ html,
57
+ _args3 = arguments;
58
+
59
+ return _regeneratorRuntime.wrap(function _callee2$(_context3) {
60
+ while (1) {
61
+ switch (_context3.prev = _context3.next) {
62
+ case 0:
63
+ _ref6 = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {}, _ref6$fallback = _ref6.fallback, fallback = _ref6$fallback === void 0 ? false : _ref6$fallback;
64
+ routeRecorder = new StaticRenderer({
65
+ forceFallback: fallback ? url.pathname : undefined
66
+ });
67
+ _context3.next = 4;
68
+ return renderApp( /*#__PURE__*/jsx(App, {}), {
69
+ url: url,
70
+ decorate: function decorate(app) {
71
+ return /*#__PURE__*/jsx(StaticRendererContext.Provider, {
72
+ value: routeRecorder,
73
+ children: app
74
+ });
75
+ }
76
+ });
77
+
78
+ case 4:
79
+ _yield$renderApp = _context3.sent;
80
+ http = _yield$renderApp.http;
81
+ htmlManager = _yield$renderApp.html;
82
+ markup = _yield$renderApp.markup;
83
+ asyncAssets = _yield$renderApp.asyncAssets;
84
+ usedAssets = asyncAssets.used({
85
+ timing: 'load'
86
+ });
87
+ _context3.next = 12;
88
+ return Promise.all([assets.styles({
89
+ async: usedAssets,
90
+ options: {
91
+ modules: true
92
+ }
93
+ }), assets.scripts({
94
+ async: usedAssets,
95
+ options: {
96
+ modules: true
97
+ }
98
+ }), assets.asyncAssets(asyncAssets.used({
99
+ timing: 'preload'
100
+ }), {
101
+ options: {
102
+ modules: true
103
+ }
104
+ }), assets.styles({
105
+ async: usedAssets,
106
+ options: {
107
+ modules: false
108
+ }
109
+ }), assets.scripts({
110
+ async: usedAssets,
111
+ options: {
112
+ modules: false
113
+ }
114
+ })]);
115
+
116
+ case 12:
117
+ _yield$Promise$all = _context3.sent;
118
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 5);
119
+ moduleStyles = _yield$Promise$all2[0];
120
+ moduleScripts = _yield$Promise$all2[1];
121
+ modulePreload = _yield$Promise$all2[2];
122
+ nomoduleStyles = _yield$Promise$all2[3];
123
+ nomoduleScripts = _yield$Promise$all2[4];
124
+ // We don’t want to load styles from both bundles, so we only use module styles,
125
+ // since modules are intended to be the default and CSS (usually) doesn’t
126
+ // have features that meaningfully break older user agents.
127
+ styles = moduleStyles.length > 0 ? moduleStyles : nomoduleStyles; // If there are nomodule scripts, we can’t really do preloading, because we can’t
128
+ // prevent the nomodule scripts from being preloaded in module browsers. If there
129
+ // are only module scripts, we can preload those.
130
+
131
+ preload = nomoduleScripts.length > 0 ? [] : modulePreload;
132
+ scripts = [].concat(_toConsumableArray(moduleScripts), _toConsumableArray(nomoduleScripts.map(function (script) {
133
+ return _objectSpread(_objectSpread({}, script), {}, {
134
+ nomodule: true
135
+ });
136
+ })));
137
+ minifiedHtml = render( /*#__PURE__*/jsx(Html, {
138
+ url: url,
139
+ manager: htmlManager,
140
+ styles: styles,
141
+ scripts: scripts,
142
+ preloadAssets: preload,
143
+ children: markup
144
+ }));
145
+
146
+ if (!prettify) {
147
+ _context3.next = 29;
148
+ break;
149
+ }
150
+
151
+ _context3.next = 26;
152
+ return prettifyHtml(minifiedHtml);
153
+
154
+ case 26:
155
+ _context3.t0 = _context3.sent;
156
+ _context3.next = 30;
157
+ break;
158
+
159
+ case 29:
160
+ _context3.t0 = minifiedHtml;
161
+
162
+ case 30:
163
+ html = _context3.t0;
164
+ return _context3.abrupt("return", {
165
+ html: html,
166
+ http: http.state,
167
+ routes: routeRecorder.state
168
+ });
169
+
170
+ case 32:
171
+ case "end":
172
+ return _context3.stop();
173
+ }
174
+ }
175
+ }, _callee2);
176
+ }));
177
+ return _renderUrl.apply(this, arguments);
178
+ };
179
+
180
+ renderUrl = function _renderUrl2(_x6) {
181
+ return _renderUrl.apply(this, arguments);
182
+ };
183
+
184
+ _recordRouteDefinition = function _recordRouteDefinitio2() {
185
+ _recordRouteDefinition = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref3, _ref4) {
186
+ var match, children, renderStatic, basePathname, baseId, addFallbacks, routeId, hasChildren, hasManualMatches, matchedRoutes, matchedRouteParts, _iterator3, _step3, routePart, id, _iterator4, _step4, _ref5, _step4$value, _id, route, _iterator5, _step5, child, _i2, _matchedRoutes, _matchedRoutes$_i, _route, fallback, _renderableRoute2;
187
+
188
+ return _regeneratorRuntime.wrap(function _callee$(_context2) {
189
+ while (1) {
190
+ switch (_context2.prev = _context2.next) {
191
+ case 0:
192
+ match = _ref3.match, children = _ref3.children, renderStatic = _ref3.renderStatic;
193
+ basePathname = _ref4.basePathname, baseId = _ref4.baseId, addFallbacks = _ref4.addFallbacks;
194
+
195
+ if (!(renderStatic === false)) {
196
+ _context2.next = 4;
197
+ break;
198
+ }
199
+
200
+ return _context2.abrupt("return");
201
+
202
+ case 4:
203
+ hasChildren = children && children.length > 0;
204
+ hasManualMatches = typeof renderStatic === 'function' && typeof match !== 'string';
205
+ matchedRoutes = [];
206
+
207
+ if (typeof match === 'string') {
208
+ routeId = joinPath(baseId, match);
209
+ matchedRoutes.push({
210
+ id: routeId,
211
+ route: joinPath(basePathname, match),
212
+ fallback: false
213
+ });
214
+ } else if (typeof match === 'function') {
215
+ routeId = joinPath(baseId, "__QUILT_FUNCTION_ROUTE_".concat(match.toString(), "__"));
216
+ } else if (match instanceof RegExp) {
217
+ routeId = joinPath("__QUILT_REGEX_ROUTE_".concat(match.source, "__"));
218
+ } else {
219
+ routeId = joinPath(baseId, '__QUILT_FALLBACK_ROUTE__');
220
+
221
+ if (!hasManualMatches) {
222
+ matchedRoutes.push({
223
+ id: routeId,
224
+ route: basePathname,
225
+ fallback: true
226
+ });
227
+ }
228
+ }
229
+
230
+ if (!seenRouteIds.has(routeId)) {
231
+ _context2.next = 10;
232
+ break;
233
+ }
234
+
235
+ return _context2.abrupt("return");
236
+
237
+ case 10:
238
+ seenRouteIds.add(routeId);
239
+
240
+ if (!(typeof renderStatic === 'function' && typeof match !== 'string')) {
241
+ _context2.next = 17;
242
+ break;
243
+ }
244
+
245
+ _context2.next = 14;
246
+ return renderStatic();
247
+
248
+ case 14:
249
+ matchedRouteParts = _context2.sent;
250
+ _iterator3 = _createForOfIteratorHelper(matchedRouteParts);
251
+
252
+ try {
253
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
254
+ routePart = _step3.value;
255
+ id = joinPath(baseId, "__QUILT_MATCH_".concat(routePart, "__"));
256
+ seenRouteIds.add(id);
257
+ matchedRoutes.push({
258
+ id: id,
259
+ route: joinPath(basePathname, routePart),
260
+ fallback: false
261
+ });
262
+ }
263
+ } catch (err) {
264
+ _iterator3.e(err);
265
+ } finally {
266
+ _iterator3.f();
267
+ }
268
+
269
+ case 17:
270
+ if (!hasChildren) {
271
+ _context2.next = 54;
272
+ break;
273
+ }
274
+
275
+ _iterator4 = _createForOfIteratorHelper(matchedRoutes);
276
+ _context2.prev = 19;
277
+
278
+ _iterator4.s();
279
+
280
+ case 21:
281
+ if ((_step4 = _iterator4.n()).done) {
282
+ _context2.next = 45;
283
+ break;
284
+ }
285
+
286
+ _step4$value = _step4.value, _id = _step4$value.id, route = _step4$value.route;
287
+ _iterator5 = _createForOfIteratorHelper(children);
288
+ _context2.prev = 24;
289
+
290
+ _iterator5.s();
291
+
292
+ case 26:
293
+ if ((_step5 = _iterator5.n()).done) {
294
+ _context2.next = 32;
295
+ break;
296
+ }
297
+
298
+ child = _step5.value;
299
+ _context2.next = 30;
300
+ return recordRouteDefinition(child, {
301
+ addFallbacks: addFallbacks,
302
+ basePathname: route,
303
+ baseId: _id
304
+ });
305
+
306
+ case 30:
307
+ _context2.next = 26;
308
+ break;
309
+
310
+ case 32:
311
+ _context2.next = 37;
312
+ break;
313
+
314
+ case 34:
315
+ _context2.prev = 34;
316
+ _context2.t0 = _context2["catch"](24);
317
+
318
+ _iterator5.e(_context2.t0);
319
+
320
+ case 37:
321
+ _context2.prev = 37;
322
+
323
+ _iterator5.f();
324
+
325
+ return _context2.finish(37);
326
+
327
+ case 40:
328
+ if (!(addFallbacks && ((_ref5 = children[children.length - 1]) === null || _ref5 === void 0 ? void 0 : _ref5.match) != null)) {
329
+ _context2.next = 43;
330
+ break;
331
+ }
332
+
333
+ _context2.next = 43;
334
+ return recordRouteDefinition({}, {
335
+ addFallbacks: addFallbacks,
336
+ basePathname: route,
337
+ baseId: _id
338
+ });
339
+
340
+ case 43:
341
+ _context2.next = 21;
342
+ break;
343
+
344
+ case 45:
345
+ _context2.next = 50;
346
+ break;
347
+
348
+ case 47:
349
+ _context2.prev = 47;
350
+ _context2.t1 = _context2["catch"](19);
143
351
 
144
- if (addFallbacks && children[children.length - 1]?.match != null) {
145
- await recordRouteDefinition({}, {
146
- addFallbacks,
147
- basePathname: route,
148
- baseId: id
149
- });
352
+ _iterator4.e(_context2.t1);
353
+
354
+ case 50:
355
+ _context2.prev = 50;
356
+
357
+ _iterator4.f();
358
+
359
+ return _context2.finish(50);
360
+
361
+ case 53:
362
+ return _context2.abrupt("return");
363
+
364
+ case 54:
365
+ for (_i2 = 0, _matchedRoutes = matchedRoutes; _i2 < _matchedRoutes.length; _i2++) {
366
+ _matchedRoutes$_i = _matchedRoutes[_i2], _route = _matchedRoutes$_i.route, fallback = _matchedRoutes$_i.fallback;
367
+ _renderableRoute2 = {
368
+ route: _route,
369
+ fallback: fallback
370
+ };
371
+ seenRoutes.push(_renderableRoute2);
372
+ routesToHandle.push(_renderableRoute2);
373
+ }
374
+
375
+ case 55:
376
+ case "end":
377
+ return _context2.stop();
378
+ }
379
+ }
380
+ }, _callee, null, [[19, 47, 50, 53], [24, 34, 37, 40]]);
381
+ }));
382
+ return _recordRouteDefinition.apply(this, arguments);
383
+ };
384
+
385
+ recordRouteDefinition = function _recordRouteDefinitio(_x4, _x5) {
386
+ return _recordRouteDefinition.apply(this, arguments);
387
+ };
388
+
389
+ assets = _ref.assets, startingRoutes = _ref.routes, onRender = _ref.onRender, _ref$crawl = _ref.crawl, crawl = _ref$crawl === void 0 ? true : _ref$crawl, _ref$baseUrl = _ref.baseUrl, baseUrl = _ref$baseUrl === void 0 ? BASE_URL : _ref$baseUrl, _ref$prettify = _ref.prettify, prettify = _ref$prettify === void 0 ? true : _ref$prettify;
390
+ routesToHandle = startingRoutes.map(function (route) {
391
+ return {
392
+ route: removePostfixSlash(new URL(route, baseUrl).pathname),
393
+ fallback: false
394
+ };
395
+ });
396
+ seenRoutes = _toConsumableArray(routesToHandle);
397
+ seenRouteIds = new Set(seenRoutes.map(function (_ref2) {
398
+ var route = _ref2.route;
399
+ return route;
400
+ }));
401
+ _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
402
+ var _renderableRoute, route, fallback, url, _yield$renderUrl, html, http, routes, _iterator, _step, _routeDefinitions, _step$value, routeDefinitions, _step$value$fallback, _fallback, consumedPath, prefix, basePathname, baseId, _iterator2, _step2, routeDefinition;
403
+
404
+ return _regeneratorRuntime.wrap(function _loop$(_context) {
405
+ while (1) {
406
+ switch (_context.prev = _context.next) {
407
+ case 0:
408
+ _renderableRoute = renderableRoute, route = _renderableRoute.route, fallback = _renderableRoute.fallback;
409
+ url = new URL(route, baseUrl);
410
+ _context.next = 4;
411
+ return renderUrl(url, {
412
+ fallback: fallback
413
+ });
414
+
415
+ case 4:
416
+ _yield$renderUrl = _context.sent;
417
+ html = _yield$renderUrl.html;
418
+ http = _yield$renderUrl.http;
419
+ routes = _yield$renderUrl.routes;
420
+
421
+ if (!crawl) {
422
+ _context.next = 46;
423
+ break;
424
+ }
425
+
426
+ _iterator = _createForOfIteratorHelper(routes);
427
+ _context.prev = 10;
428
+
429
+ _iterator.s();
430
+
431
+ case 12:
432
+ if ((_step = _iterator.n()).done) {
433
+ _context.next = 38;
434
+ break;
435
+ }
436
+
437
+ _step$value = _step.value, routeDefinitions = _step$value.routes, _step$value$fallback = _step$value.fallback, _fallback = _step$value$fallback === void 0 ? false : _step$value$fallback, consumedPath = _step$value.consumedPath, prefix = _step$value.prefix;
438
+ basePathname = joinPath(prefix, consumedPath);
439
+ baseId = basePathname === '/' ? basePathname : "__QUILT_BASE_".concat(basePathname, "__");
440
+ _iterator2 = _createForOfIteratorHelper(routeDefinitions);
441
+ _context.prev = 17;
442
+
443
+ _iterator2.s();
444
+
445
+ case 19:
446
+ if ((_step2 = _iterator2.n()).done) {
447
+ _context.next = 25;
448
+ break;
449
+ }
450
+
451
+ routeDefinition = _step2.value;
452
+ _context.next = 23;
453
+ return recordRouteDefinition(routeDefinition, {
454
+ baseId: baseId,
455
+ basePathname: basePathname,
456
+ addFallbacks: _fallback
457
+ });
458
+
459
+ case 23:
460
+ _context.next = 19;
461
+ break;
462
+
463
+ case 25:
464
+ _context.next = 30;
465
+ break;
466
+
467
+ case 27:
468
+ _context.prev = 27;
469
+ _context.t0 = _context["catch"](17);
470
+
471
+ _iterator2.e(_context.t0);
472
+
473
+ case 30:
474
+ _context.prev = 30;
475
+
476
+ _iterator2.f();
477
+
478
+ return _context.finish(30);
479
+
480
+ case 33:
481
+ if (!(_fallback && ((_routeDefinitions = routeDefinitions[routeDefinitions.length - 1]) === null || _routeDefinitions === void 0 ? void 0 : _routeDefinitions.match) != null)) {
482
+ _context.next = 36;
483
+ break;
484
+ }
485
+
486
+ _context.next = 36;
487
+ return recordRouteDefinition({}, {
488
+ baseId: baseId,
489
+ basePathname: basePathname,
490
+ addFallbacks: _fallback
491
+ });
492
+
493
+ case 36:
494
+ _context.next = 12;
495
+ break;
496
+
497
+ case 38:
498
+ _context.next = 43;
499
+ break;
500
+
501
+ case 40:
502
+ _context.prev = 40;
503
+ _context.t1 = _context["catch"](10);
504
+
505
+ _iterator.e(_context.t1);
506
+
507
+ case 43:
508
+ _context.prev = 43;
509
+
510
+ _iterator.f();
511
+
512
+ return _context.finish(43);
513
+
514
+ case 46:
515
+ _context.next = 48;
516
+ return onRender({
517
+ route: route,
518
+ content: html,
519
+ http: http,
520
+ fallback: fallback,
521
+ hasChildren: !fallback && seenRoutes.some(function (otherRoute) {
522
+ return otherRoute.route.startsWith("".concat(route, "/"));
523
+ })
524
+ });
525
+
526
+ case 48:
527
+ case "end":
528
+ return _context.stop();
529
+ }
530
+ }
531
+ }, _loop, null, [[10, 40, 43, 46], [17, 27, 30, 33]]);
532
+ });
533
+
534
+ case 9:
535
+ if (!(renderableRoute = routesToHandle.shift())) {
536
+ _context4.next = 13;
537
+ break;
538
+ }
539
+
540
+ return _context4.delegateYield(_loop(), "t0", 11);
541
+
542
+ case 11:
543
+ _context4.next = 9;
544
+ break;
545
+
546
+ case 13:
547
+ case "end":
548
+ return _context4.stop();
150
549
  }
151
550
  }
551
+ }, _callee3);
552
+ }));
553
+ return _renderStatic.apply(this, arguments);
554
+ }
152
555
 
153
- return;
154
- }
155
-
156
- for (const {
157
- route,
158
- fallback
159
- } of matchedRoutes) {
160
- const renderableRoute = {
161
- route,
162
- fallback
163
- };
164
- seenRoutes.push(renderableRoute);
165
- routesToHandle.push(renderableRoute);
166
- }
167
- }
556
+ function prettifyHtml(_x3) {
557
+ return _prettifyHtml.apply(this, arguments);
558
+ }
168
559
 
169
- async function renderUrl(url, {
170
- fallback = false
171
- }) {
172
- const routeRecorder = new StaticRenderer({
173
- forceFallback: fallback ? url.pathname : undefined
174
- });
175
- const {
176
- http,
177
- html: htmlManager,
178
- markup,
179
- asyncAssets
180
- } = await renderApp( /*#__PURE__*/jsx(App, {}), {
181
- url,
182
-
183
- decorate(app) {
184
- return /*#__PURE__*/jsx(StaticRendererContext.Provider, {
185
- value: routeRecorder,
186
- children: app
187
- });
188
- }
560
+ function _prettifyHtml() {
561
+ _prettifyHtml = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(html) {
562
+ var _yield$import, prettier;
189
563
 
190
- });
191
- const usedAssets = asyncAssets.used({
192
- timing: 'load'
193
- });
194
- const [moduleStyles, moduleScripts, modulePreload, nomoduleStyles, nomoduleScripts] = await Promise.all([assets.styles({
195
- async: usedAssets,
196
- options: {
197
- modules: true
198
- }
199
- }), assets.scripts({
200
- async: usedAssets,
201
- options: {
202
- modules: true
203
- }
204
- }), assets.asyncAssets(asyncAssets.used({
205
- timing: 'preload'
206
- }), {
207
- options: {
208
- modules: true
209
- }
210
- }), assets.styles({
211
- async: usedAssets,
212
- options: {
213
- modules: false
214
- }
215
- }), assets.scripts({
216
- async: usedAssets,
217
- options: {
218
- modules: false
564
+ return _regeneratorRuntime.wrap(function _callee4$(_context5) {
565
+ while (1) {
566
+ switch (_context5.prev = _context5.next) {
567
+ case 0:
568
+ _context5.prev = 0;
569
+ _context5.next = 3;
570
+ return import('prettier');
571
+
572
+ case 3:
573
+ _yield$import = _context5.sent;
574
+ prettier = _yield$import["default"];
575
+ return _context5.abrupt("return", prettier.format(html, {
576
+ parser: 'html'
577
+ }));
578
+
579
+ case 8:
580
+ _context5.prev = 8;
581
+ _context5.t0 = _context5["catch"](0);
582
+ return _context5.abrupt("return", html);
583
+
584
+ case 11:
585
+ case "end":
586
+ return _context5.stop();
587
+ }
219
588
  }
220
- })]); // We don’t want to load styles from both bundles, so we only use module styles,
221
- // since modules are intended to be the default and CSS (usually) doesn’t
222
- // have features that meaningfully break older user agents.
223
-
224
- const styles = moduleStyles.length > 0 ? moduleStyles : nomoduleStyles; // If there are nomodule scripts, we can’t really do preloading, because we can’t
225
- // prevent the nomodule scripts from being preloaded in module browsers. If there
226
- // are only module scripts, we can preload those.
227
-
228
- const preload = nomoduleScripts.length > 0 ? [] : modulePreload;
229
- const scripts = [...moduleScripts, ...nomoduleScripts.map(script => ({ ...script,
230
- nomodule: true
231
- }))];
232
- const minifiedHtml = render( /*#__PURE__*/jsx(Html, {
233
- url: url,
234
- manager: htmlManager,
235
- styles: styles,
236
- scripts: scripts,
237
- preloadAssets: preload,
238
- children: markup
239
- }));
240
- const html = prettify ? await prettifyHtml(minifiedHtml) : minifiedHtml;
241
- return {
242
- html,
243
- http: http.state,
244
- routes: routeRecorder.state
245
- };
246
- }
589
+ }, _callee4, null, [[0, 8]]);
590
+ }));
591
+ return _prettifyHtml.apply(this, arguments);
247
592
  }
248
593
 
249
- async function prettifyHtml(html) {
250
- try {
251
- const {
252
- default: prettier
253
- } = await import('prettier');
254
- return prettier.format(html, {
255
- parser: 'html'
256
- });
257
- } catch (error) {
258
- return html;
259
- }
260
- }
594
+ function joinPath() {
595
+ var path = '/';
261
596
 
262
- function joinPath(...parts) {
263
- let path = '/';
597
+ for (var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++) {
598
+ parts[_key] = arguments[_key];
599
+ }
264
600
 
265
- for (const part of parts) {
601
+ for (var _i = 0, _parts = parts; _i < _parts.length; _i++) {
602
+ var part = _parts[_i];
266
603
  if (typeof part !== 'string') continue;
267
- const normalizedPart = part.startsWith('/') ? part.slice(1) : part;
604
+ var normalizedPart = part.startsWith('/') ? part.slice(1) : part;
268
605
  if (normalizedPart.length === 0) continue;
269
606
  if (path !== '/') path += '/';
270
607
  path += normalizedPart;