@quilted/quilt 0.5.105 → 0.5.106
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 +10 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -23
- package/quilt.project.ts +3 -38
- package/tsconfig.json +1 -1
- package/build/cjs/AppContext.cjs +0 -22
- package/build/cjs/email.cjs +0 -32
- package/build/cjs/env.cjs +0 -7
- package/build/cjs/global.cjs +0 -5
- package/build/cjs/html.cjs +0 -112
- package/build/cjs/http-handlers/index.cjs +0 -14
- package/build/cjs/http-handlers/node.cjs +0 -14
- package/build/cjs/http.cjs +0 -108
- package/build/cjs/index.cjs +0 -216
- package/build/cjs/matchers.cjs +0 -5
- package/build/cjs/polyfills/abort-controller.cjs +0 -4
- package/build/cjs/polyfills/base.cjs +0 -4
- package/build/cjs/polyfills/crypto.cjs +0 -4
- package/build/cjs/polyfills/fetch.cjs +0 -4
- package/build/cjs/polyfills/noop.cjs +0 -4
- package/build/cjs/server/ServerContext.cjs +0 -22
- package/build/cjs/server/http-handler.cjs +0 -88
- package/build/cjs/server/index.cjs +0 -119
- package/build/cjs/server/render.cjs +0 -44
- package/build/cjs/static/StaticContext.cjs +0 -22
- package/build/cjs/static/index.cjs +0 -303
- package/build/cjs/static/render.cjs +0 -44
- package/build/cjs/testing.cjs +0 -61
- package/build/cjs/threads.cjs +0 -74
- package/build/cjs/utilities/react.cjs +0 -14
- package/build/esm/AppContext.mjs +0 -18
- package/build/esm/email.mjs +0 -1
- package/build/esm/env.mjs +0 -3
- package/build/esm/global.mjs +0 -3
- package/build/esm/html.mjs +0 -1
- package/build/esm/http-handlers/index.mjs +0 -1
- package/build/esm/http-handlers/node.mjs +0 -1
- package/build/esm/http.mjs +0 -1
- package/build/esm/index.mjs +0 -12
- package/build/esm/matchers.mjs +0 -2
- package/build/esm/polyfills/abort-controller.mjs +0 -1
- package/build/esm/polyfills/base.mjs +0 -1
- package/build/esm/polyfills/crypto.mjs +0 -1
- package/build/esm/polyfills/fetch.mjs +0 -1
- package/build/esm/polyfills/noop.mjs +0 -1
- package/build/esm/server/ServerContext.mjs +0 -18
- package/build/esm/server/http-handler.mjs +0 -82
- package/build/esm/server/index.mjs +0 -11
- package/build/esm/server/render.mjs +0 -40
- package/build/esm/static/StaticContext.mjs +0 -18
- package/build/esm/static/index.mjs +0 -281
- package/build/esm/static/render.mjs +0 -40
- package/build/esm/testing.mjs +0 -4
- package/build/esm/threads.mjs +0 -3
- package/build/esm/utilities/react.mjs +0 -10
- package/build/esnext/AppContext.esnext +0 -18
- package/build/esnext/email.esnext +0 -1
- package/build/esnext/env.esnext +0 -3
- package/build/esnext/global.esnext +0 -3
- package/build/esnext/html.esnext +0 -1
- package/build/esnext/http-handlers/index.esnext +0 -1
- package/build/esnext/http-handlers/node.esnext +0 -1
- package/build/esnext/http.esnext +0 -1
- package/build/esnext/index.esnext +0 -12
- package/build/esnext/matchers.esnext +0 -2
- package/build/esnext/polyfills/abort-controller.esnext +0 -1
- package/build/esnext/polyfills/base.esnext +0 -1
- package/build/esnext/polyfills/crypto.esnext +0 -1
- package/build/esnext/polyfills/fetch.esnext +0 -1
- package/build/esnext/polyfills/noop.esnext +0 -1
- package/build/esnext/server/ServerContext.esnext +0 -18
- package/build/esnext/server/http-handler.esnext +0 -82
- package/build/esnext/server/index.esnext +0 -11
- package/build/esnext/server/render.esnext +0 -40
- package/build/esnext/static/StaticContext.esnext +0 -18
- package/build/esnext/static/index.esnext +0 -281
- package/build/esnext/static/render.esnext +0 -40
- package/build/esnext/testing.esnext +0 -4
- package/build/esnext/threads.esnext +0 -3
- package/build/esnext/utilities/react.esnext +0 -10
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import { render, Html } from '@quilted/react-html/server';
|
|
2
|
-
import { StaticRenderer, StaticRendererContext } from '@quilted/react-router/static';
|
|
3
|
-
import { renderApp } from './render.esnext';
|
|
4
|
-
import { jsx } from 'react/jsx-runtime';
|
|
5
|
-
|
|
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
|
-
}
|
|
56
|
-
|
|
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
|
-
}
|
|
75
|
-
|
|
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
|
-
}
|
|
143
|
-
|
|
144
|
-
if (addFallbacks && children[children.length - 1]?.match != null) {
|
|
145
|
-
await recordRouteDefinition({}, {
|
|
146
|
-
addFallbacks,
|
|
147
|
-
basePathname: route,
|
|
148
|
-
baseId: id
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
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
|
-
}
|
|
168
|
-
|
|
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
|
-
}
|
|
189
|
-
|
|
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
|
|
219
|
-
}
|
|
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
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
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
|
-
}
|
|
261
|
-
|
|
262
|
-
function joinPath(...parts) {
|
|
263
|
-
let path = '/';
|
|
264
|
-
|
|
265
|
-
for (const part of parts) {
|
|
266
|
-
if (typeof part !== 'string') continue;
|
|
267
|
-
const normalizedPart = part.startsWith('/') ? part.slice(1) : part;
|
|
268
|
-
if (normalizedPart.length === 0) continue;
|
|
269
|
-
if (path !== '/') path += '/';
|
|
270
|
-
path += normalizedPart;
|
|
271
|
-
path = removePostfixSlash(path);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return path;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
function removePostfixSlash(value) {
|
|
278
|
-
return value.endsWith('/') && value !== '/' ? value.slice(0, value.length - 1) : value;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
export { renderStatic };
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { extract } from '@quilted/react-server-render/server';
|
|
2
|
-
import { HtmlManager } from '@quilted/react-html/server';
|
|
3
|
-
import { HttpManager } from '@quilted/react-http/server';
|
|
4
|
-
import { AsyncAssetManager } from '@quilted/react-async/server';
|
|
5
|
-
import { StaticContext } from './StaticContext.esnext';
|
|
6
|
-
import { jsx } from 'react/jsx-runtime';
|
|
7
|
-
|
|
8
|
-
async function renderApp(app, {
|
|
9
|
-
decorate,
|
|
10
|
-
url,
|
|
11
|
-
headers,
|
|
12
|
-
...rest
|
|
13
|
-
}) {
|
|
14
|
-
const html = new HtmlManager();
|
|
15
|
-
const asyncAssets = new AsyncAssetManager();
|
|
16
|
-
const http = new HttpManager({
|
|
17
|
-
headers
|
|
18
|
-
});
|
|
19
|
-
const markup = await extract(app, {
|
|
20
|
-
decorate(app) {
|
|
21
|
-
return /*#__PURE__*/jsx(StaticContext, {
|
|
22
|
-
asyncAssets: asyncAssets,
|
|
23
|
-
html: html,
|
|
24
|
-
http: http,
|
|
25
|
-
url: url,
|
|
26
|
-
children: decorate?.(app) ?? app
|
|
27
|
-
});
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
...rest
|
|
31
|
-
});
|
|
32
|
-
return {
|
|
33
|
-
markup,
|
|
34
|
-
http,
|
|
35
|
-
html,
|
|
36
|
-
asyncAssets
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export { renderApp };
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export * from '@quilted/testing';
|
|
2
|
-
export { createMount, mount, mounted, unmountAll } from '@quilted/react-testing';
|
|
3
|
-
export { TestRouter, createTestRouter } from '@quilted/react-router/testing';
|
|
4
|
-
export { GraphQLController, TestGraphQL, createFiller, createGraphQLController, createSchema } from '@quilted/react-graphql/testing';
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { acceptThreadAbortSignal, createThread, createThreadAbortSignal, release, retain, targetFromBrowserWebSocket, targetFromMessagePort, targetFromWebWorker } from '@quilted/threads';
|
|
2
|
-
export { AbortError, NestedAbortController, createEmitter, on, once } from '@quilted/events';
|
|
3
|
-
export { createThreadWorker, createWorker, useThreadWorker } from '@quilted/react-workers';
|