@quilted/quilt 0.5.109 → 0.5.111
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/AppContext.cjs +22 -0
- package/build/cjs/email.cjs +32 -0
- package/build/cjs/env.cjs +7 -0
- package/build/cjs/global.cjs +5 -0
- package/build/cjs/html.cjs +112 -0
- package/build/cjs/http-handlers/index.cjs +14 -0
- package/build/cjs/http-handlers/node.cjs +14 -0
- package/build/cjs/http.cjs +108 -0
- package/build/cjs/index.cjs +261 -0
- package/build/cjs/matchers.cjs +5 -0
- package/build/cjs/polyfills/abort-controller.cjs +4 -0
- package/build/cjs/polyfills/base.cjs +4 -0
- package/build/cjs/polyfills/crypto.cjs +4 -0
- package/build/cjs/polyfills/fetch.cjs +4 -0
- package/build/cjs/polyfills/noop.cjs +4 -0
- package/build/cjs/server/ServerContext.cjs +22 -0
- package/build/cjs/server/http-handler.cjs +90 -0
- package/build/cjs/server/index.cjs +119 -0
- package/build/cjs/server/render.cjs +46 -0
- package/build/cjs/static/StaticContext.cjs +22 -0
- package/build/cjs/static/index.cjs +307 -0
- package/build/cjs/static/render.cjs +46 -0
- package/build/cjs/testing.cjs +61 -0
- package/build/cjs/threads.cjs +74 -0
- package/build/cjs/utilities/react.cjs +14 -0
- package/build/esm/AppContext.mjs +18 -0
- package/build/esm/email.mjs +1 -0
- package/build/esm/env.mjs +3 -0
- package/build/esm/global.mjs +3 -0
- package/build/esm/html.mjs +1 -0
- package/build/esm/http-handlers/index.mjs +1 -0
- package/build/esm/http-handlers/node.mjs +1 -0
- package/build/esm/http.mjs +1 -0
- package/build/esm/index.mjs +13 -0
- package/build/esm/matchers.mjs +2 -0
- package/build/esm/polyfills/abort-controller.mjs +1 -0
- package/build/esm/polyfills/base.mjs +1 -0
- package/build/esm/polyfills/crypto.mjs +1 -0
- package/build/esm/polyfills/fetch.mjs +1 -0
- package/build/esm/polyfills/noop.mjs +1 -0
- package/build/esm/server/ServerContext.mjs +18 -0
- package/build/esm/server/http-handler.mjs +84 -0
- package/build/esm/server/index.mjs +11 -0
- package/build/esm/server/render.mjs +42 -0
- package/build/esm/static/StaticContext.mjs +18 -0
- package/build/esm/static/index.mjs +285 -0
- package/build/esm/static/render.mjs +42 -0
- package/build/esm/testing.mjs +4 -0
- package/build/esm/threads.mjs +3 -0
- package/build/esm/utilities/react.mjs +10 -0
- package/build/esnext/AppContext.esnext +18 -0
- package/build/esnext/email.esnext +1 -0
- package/build/esnext/env.esnext +3 -0
- package/build/esnext/global.esnext +3 -0
- package/build/esnext/html.esnext +1 -0
- package/build/esnext/http-handlers/index.esnext +1 -0
- package/build/esnext/http-handlers/node.esnext +1 -0
- package/build/esnext/http.esnext +1 -0
- package/build/esnext/index.esnext +13 -0
- package/build/esnext/matchers.esnext +2 -0
- package/build/esnext/polyfills/abort-controller.esnext +1 -0
- package/build/esnext/polyfills/base.esnext +1 -0
- package/build/esnext/polyfills/crypto.esnext +1 -0
- package/build/esnext/polyfills/fetch.esnext +1 -0
- package/build/esnext/polyfills/noop.esnext +1 -0
- package/build/esnext/server/ServerContext.esnext +18 -0
- package/build/esnext/server/http-handler.esnext +82 -0
- package/build/esnext/server/index.esnext +11 -0
- package/build/esnext/server/render.esnext +40 -0
- package/build/esnext/static/StaticContext.esnext +18 -0
- package/build/esnext/static/index.esnext +281 -0
- package/build/esnext/static/render.esnext +40 -0
- package/build/esnext/testing.esnext +4 -0
- package/build/esnext/threads.esnext +3 -0
- package/build/esnext/utilities/react.esnext +10 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/index.d.ts +2 -1
- package/build/typescript/index.d.ts.map +1 -1
- package/package.json +2 -1
- package/source/index.ts +17 -1
- package/tsconfig.json +1 -0
|
@@ -0,0 +1,3 @@
|
|
|
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';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HttpContext, CookieContext } from '@quilted/react-http';
|
|
2
|
+
import { useHtmlUpdater } from '@quilted/react-html';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
// TODO: have craft options to remove the bundle impact of parts of this that are
|
|
6
|
+
// unused.
|
|
7
|
+
function AppContext({
|
|
8
|
+
children
|
|
9
|
+
}) {
|
|
10
|
+
useHtmlUpdater();
|
|
11
|
+
return /*#__PURE__*/jsx(HttpContext, {
|
|
12
|
+
children: /*#__PURE__*/jsx(CookieContext, {
|
|
13
|
+
children: children
|
|
14
|
+
})
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { AppContext };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { usePlainTextContent, useSendBcc, useSendCc, useSendTo, useSender, useSubject } from '@quilted/react-email';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Alternate, BodyAttributes, Favicon, HtmlAttributes, Hydrator, Link, Meta, SearchRobots, Serialize, ThemeColor, Title, Viewport, getSerialized, useAlternateUrl, useBodyAttributes, useFavicon, useHtmlAttributes, useHtmlUpdater, useLink, useLocale, useMeta, useSearchRobots, useSerialized, useThemeColor, useTitle, useViewport } from '@quilted/react-html';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@quilted/http-handlers';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@quilted/http-handlers/node';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CacheControl, ContentSecurityPolicy, ContentSecurityPolicyDirective, ContentSecurityPolicySandboxAllow, ContentSecurityPolicySpecialSource, HttpContext, HttpMethod, NotFound, PermissionsPolicy, ResponseCookie, ResponseHeader, ResponseStatus, ResponseType, StatusCode, StrictTransportSecurity, useCacheControl, useContentSecurityPolicy, useDeleteResponseCookie, usePermissionsPolicy, useRequestHeader, useResponseCookie, useResponseHeader, useResponseRedirect, useResponseStatus, useStrictTransportSecurity } from '@quilted/react-http';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { createAsyncLoader } from '@quilted/async';
|
|
2
|
+
export { AbortError, NestedAbortController, createEmitter, on, once } from '@quilted/events';
|
|
3
|
+
export { createAsyncComponent, useAsync, useAsyncAsset, usePreload } from '@quilted/react-async';
|
|
4
|
+
export { GraphQLContext, createGraphQLHttpFetch, useGraphQLFetch } from '@quilted/react-graphql';
|
|
5
|
+
export { useIdleCallback } from '@quilted/react-idle';
|
|
6
|
+
export { ServerAction, useServerAction, useServerContext } from '@quilted/react-server-render';
|
|
7
|
+
export { Localization, LocalizedLink, LocalizedRouter, createRouteLocalization, createRoutePathLocalization, createRouteSubdomainLocalization, useLocale, useLocaleFromEnvironment, useLocalizedFormatting, useRouteLocalization } from '@quilted/react-localize';
|
|
8
|
+
export { PerformanceContext, usePerformance, usePerformanceNavigation } from '@quilted/react-performance';
|
|
9
|
+
export { Link, NavigationBlock, Preloader, Redirect, Router, useCurrentUrl, useInitialUrl, useMatch, useNavigate, useNavigationBlock, useRedirect, useRouteChangeFocusRef, useRouter, useRoutes, useScrollRestoration } from '@quilted/react-router';
|
|
10
|
+
export { CookieContext, useCookie, useCookies } from '@quilted/react-http';
|
|
11
|
+
export { createOptionalContext, createUseContextHook } from '@quilted/react-utilities';
|
|
12
|
+
export { Signal, computed as computedSignal, isSignal, resolveSignalOrValue, signal, batch as signalBatch, effect as signalEffect, useComputed, useSignal, useSignalEffect } from '@quilted/react-signals';
|
|
13
|
+
export { AppContext } from './AppContext.esnext';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@quilted/polyfills/abort-controller';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@quilted/polyfills/base';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@quilted/polyfills/crypto';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@quilted/polyfills/fetch';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@quilted/polyfills/noop';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InitialUrlContext } from '@quilted/react-router';
|
|
2
|
+
import { HtmlContext } from '@quilted/react-html/server';
|
|
3
|
+
import { AsyncAssetContext } from '@quilted/react-async/server';
|
|
4
|
+
import { HttpServerContext } from '@quilted/react-http/server';
|
|
5
|
+
import { maybeWrapContext } from '../utilities/react.esnext';
|
|
6
|
+
|
|
7
|
+
function ServerContext({
|
|
8
|
+
url,
|
|
9
|
+
html,
|
|
10
|
+
http,
|
|
11
|
+
asyncAssets,
|
|
12
|
+
children
|
|
13
|
+
}) {
|
|
14
|
+
const normalizedUrl = typeof url === 'string' ? new URL(url) : url;
|
|
15
|
+
return maybeWrapContext(AsyncAssetContext, asyncAssets, maybeWrapContext(HttpServerContext, http, maybeWrapContext(HtmlContext, html, maybeWrapContext(InitialUrlContext, normalizedUrl, children))));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { ServerContext };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { render, Html } from '@quilted/react-html/server';
|
|
2
|
+
import { createHttpHandler, redirect, html } from '@quilted/http-handlers';
|
|
3
|
+
import { renderApp } from './render.esnext';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
function createServerRenderingHttpHandler(render, {
|
|
7
|
+
handler = createHttpHandler(),
|
|
8
|
+
...options
|
|
9
|
+
}) {
|
|
10
|
+
handler.get(createServerRenderingRequestHandler(render, options));
|
|
11
|
+
return handler;
|
|
12
|
+
}
|
|
13
|
+
function createServerRenderingRequestHandler(render, {
|
|
14
|
+
context,
|
|
15
|
+
...options
|
|
16
|
+
} = {}) {
|
|
17
|
+
return async (request, requestContext) => {
|
|
18
|
+
const app = await render(request, requestContext);
|
|
19
|
+
return renderToResponse(app, request, { ...options,
|
|
20
|
+
context: context?.(request, requestContext) ?? requestContext
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async function renderToResponse(app, request, {
|
|
25
|
+
assets,
|
|
26
|
+
...options
|
|
27
|
+
} = {}) {
|
|
28
|
+
const accepts = request.headers.get('Accept');
|
|
29
|
+
if (accepts != null && !accepts.includes('text/html')) return;
|
|
30
|
+
const {
|
|
31
|
+
html: htmlManager,
|
|
32
|
+
http,
|
|
33
|
+
markup,
|
|
34
|
+
asyncAssets
|
|
35
|
+
} = await renderApp(app, { ...options,
|
|
36
|
+
url: request.url,
|
|
37
|
+
headers: request.headers
|
|
38
|
+
});
|
|
39
|
+
const {
|
|
40
|
+
headers,
|
|
41
|
+
statusCode = 200,
|
|
42
|
+
redirectUrl
|
|
43
|
+
} = http.state;
|
|
44
|
+
|
|
45
|
+
if (redirectUrl) {
|
|
46
|
+
return redirect(redirectUrl, {
|
|
47
|
+
status: statusCode,
|
|
48
|
+
headers
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const usedAssets = asyncAssets.used({
|
|
53
|
+
timing: 'load'
|
|
54
|
+
});
|
|
55
|
+
const assetOptions = {
|
|
56
|
+
userAgent: request.headers.get('User-Agent')
|
|
57
|
+
};
|
|
58
|
+
const [styles, scripts, preload] = assets ? await Promise.all([assets.styles({
|
|
59
|
+
async: usedAssets,
|
|
60
|
+
options: assetOptions
|
|
61
|
+
}), assets.scripts({
|
|
62
|
+
async: usedAssets,
|
|
63
|
+
options: assetOptions
|
|
64
|
+
}), assets.asyncAssets(asyncAssets.used({
|
|
65
|
+
timing: 'preload'
|
|
66
|
+
}), {
|
|
67
|
+
options: assetOptions
|
|
68
|
+
})]) : [];
|
|
69
|
+
return html(render( /*#__PURE__*/jsx(Html, {
|
|
70
|
+
url: new URL(request.url),
|
|
71
|
+
manager: htmlManager,
|
|
72
|
+
styles: styles,
|
|
73
|
+
scripts: scripts,
|
|
74
|
+
preloadAssets: preload,
|
|
75
|
+
children: markup
|
|
76
|
+
})), {
|
|
77
|
+
headers,
|
|
78
|
+
status: statusCode
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { createServerRenderingHttpHandler, createServerRenderingRequestHandler, renderToResponse };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { SERVER_ACTION_ID as HTML_SERVER_ACTION_ID, Html, HtmlContext, HtmlManager, Serialize, render } from '@quilted/react-html/server';
|
|
2
|
+
export { ServerAction, ServerRenderManager, ServerRenderManagerContext, extract, useServerAction } from '@quilted/react-server-render/server';
|
|
3
|
+
export { createAssetManifest } from '@quilted/async/server';
|
|
4
|
+
export { SERVER_ACTION_ID as ASYNC_ASSETS_SERVER_ACTION_ID, AsyncAssetContext, AsyncAssetManager } from '@quilted/react-async/server';
|
|
5
|
+
export { renderEmail } from '@quilted/react-email/server';
|
|
6
|
+
export { createHttpHandlerLocalization } from '@quilted/react-localize/http-handlers';
|
|
7
|
+
export { EnhancedRequest, EnhancedResponse, Request, Response, createHeaders, createHttpHandler } from '@quilted/http-handlers';
|
|
8
|
+
export { parseAcceptLanguageHeader } from '@quilted/react-localize';
|
|
9
|
+
export { renderApp } from './render.esnext';
|
|
10
|
+
export { ServerContext } from './ServerContext.esnext';
|
|
11
|
+
export { createServerRenderingHttpHandler, createServerRenderingRequestHandler, renderToResponse } from './http-handler.esnext';
|
|
@@ -0,0 +1,40 @@
|
|
|
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 { ServerContext } from './ServerContext.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(ServerContext, {
|
|
22
|
+
asyncAssets: asyncAssets,
|
|
23
|
+
http: http,
|
|
24
|
+
html: html,
|
|
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 };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InitialUrlContext } from '@quilted/react-router';
|
|
2
|
+
import { HtmlContext } from '@quilted/react-html/server';
|
|
3
|
+
import { AsyncAssetContext } from '@quilted/react-async/server';
|
|
4
|
+
import { HttpServerContext } from '@quilted/react-http/server';
|
|
5
|
+
import { maybeWrapContext } from '../utilities/react.esnext';
|
|
6
|
+
|
|
7
|
+
function StaticContext({
|
|
8
|
+
url,
|
|
9
|
+
html,
|
|
10
|
+
http,
|
|
11
|
+
asyncAssets,
|
|
12
|
+
children
|
|
13
|
+
}) {
|
|
14
|
+
const normalizedUrl = typeof url === 'string' ? new URL(url) : url;
|
|
15
|
+
return maybeWrapContext(AsyncAssetContext, asyncAssets, maybeWrapContext(HttpServerContext, http, maybeWrapContext(HtmlContext, html, maybeWrapContext(InitialUrlContext, normalizedUrl, children))));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { StaticContext };
|
|
@@ -0,0 +1,281 @@
|
|
|
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 };
|
|
@@ -0,0 +1,40 @@
|
|
|
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 };
|
|
@@ -0,0 +1,4 @@
|
|
|
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';
|
|
@@ -0,0 +1,3 @@
|
|
|
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';
|