@quilted/quilt 0.5.64 → 0.5.67
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 +22 -0
- package/build/cjs/html.cjs +4 -0
- package/build/cjs/server/http-handler.cjs +69 -58
- package/build/cjs/server/index.cjs +1 -0
- package/build/esm/html.mjs +1 -1
- package/build/esm/server/http-handler.mjs +70 -60
- package/build/esm/server/index.mjs +1 -1
- package/build/esnext/html.esnext +1 -1
- package/build/esnext/server/http-handler.esnext +70 -60
- package/build/esnext/server/index.esnext +1 -1
- package/build/tsconfig.tsbuildinfo +1 -7498
- package/build/typescript/html.d.ts +2 -1
- package/build/typescript/html.d.ts.map +1 -1
- package/build/typescript/polyfills/crypto.d.ts +2 -0
- package/build/typescript/polyfills/crypto.d.ts.map +1 -0
- package/build/typescript/server/http-handler.d.ts +13 -6
- package/build/typescript/server/http-handler.d.ts.map +1 -1
- package/build/typescript/server/index.d.ts +1 -1
- package/build/typescript/server/index.d.ts.map +1 -1
- package/package.json +10 -1
- package/src/html.ts +2 -0
- package/src/polyfills/crypto.ts +1 -0
- package/src/server/http-handler.tsx +75 -60
- package/src/server/index.ts +1 -0
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { Alternate, BodyAttributes, HtmlAttributes, Hydrator, Link, Meta, SearchRobots, ThemeColor, Title, Viewport, Favicon, useAlternateUrl, useSerialized, useBodyAttributes, useHtmlAttributes, useFavicon, useLink, useLocale, useMeta, useSearchRobots, useThemeColor, useTitle, useViewport, useHtmlUpdater, getSerialized, } from '@quilted/react-html';
|
|
1
|
+
export { Alternate, BodyAttributes, HtmlAttributes, Hydrator, Link, Meta, SearchRobots, Serialize, ThemeColor, Title, Viewport, Favicon, useAlternateUrl, useSerialized, useBodyAttributes, useHtmlAttributes, useFavicon, useLink, useLocale, useMeta, useSearchRobots, useThemeColor, useTitle, useViewport, useHtmlUpdater, getSerialized, } from '@quilted/react-html';
|
|
2
|
+
export type { Serializable } from '@quilted/react-html';
|
|
2
3
|
//# sourceMappingURL=html.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/html.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,cAAc,EACd,cAAc,EACd,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,YAAY,EACZ,UAAU,EACV,KAAK,EACL,QAAQ,EACR,OAAO,EACP,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,OAAO,EACP,SAAS,EACT,OAAO,EACP,eAAe,EACf,aAAa,EACb,QAAQ,EACR,WAAW,EACX,cAAc,EACd,aAAa,GACd,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/html.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,cAAc,EACd,cAAc,EACd,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,YAAY,EACZ,SAAS,EACT,UAAU,EACV,KAAK,EACL,QAAQ,EACR,OAAO,EACP,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,OAAO,EACP,SAAS,EACT,OAAO,EACP,eAAe,EACf,aAAa,EACb,QAAQ,EACR,WAAW,EACX,cAAc,EACd,aAAa,GACd,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/polyfills/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC"}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import type { ComponentType } from 'react';
|
|
1
|
+
import type { ComponentType, ReactElement } from 'react';
|
|
2
2
|
import type { AssetLoader } from '@quilted/async/server';
|
|
3
|
-
import type { HttpHandler, RequestHandler
|
|
4
|
-
export interface Options
|
|
5
|
-
assets
|
|
3
|
+
import type { Request, HttpHandler, RequestHandler } from '@quilted/http-handlers';
|
|
4
|
+
export interface Options<Props = Record<string, never>> {
|
|
5
|
+
assets?: AssetLoader<unknown>;
|
|
6
6
|
handler?: HttpHandler;
|
|
7
|
+
renderProps?(options: {
|
|
8
|
+
request: Request;
|
|
9
|
+
}): Props;
|
|
7
10
|
}
|
|
8
|
-
export declare function createServerRenderingRequestHandler(App: ComponentType<
|
|
9
|
-
export declare function createServerRenderingHttpHandler(App: ComponentType<
|
|
11
|
+
export declare function createServerRenderingRequestHandler<Props>(App: ComponentType<Props>, { assets, renderProps }?: Pick<Options<Props>, 'assets' | 'renderProps'>): RequestHandler;
|
|
12
|
+
export declare function createServerRenderingHttpHandler<Props>(App: ComponentType<Props>, { assets, renderProps, handler }: Options<Props>): HttpHandler;
|
|
13
|
+
export declare function renderToResponse(element: ReactElement<any>, request: Request, { assets }?: {
|
|
14
|
+
assets?: AssetLoader<unknown>;
|
|
15
|
+
request?: Request;
|
|
16
|
+
}): Promise<import("@quilted/http-handlers").Response | undefined>;
|
|
10
17
|
//# sourceMappingURL=http-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-handler.d.ts","sourceRoot":"","sources":["../../../src/server/http-handler.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"http-handler.d.ts","sourceRoot":"","sources":["../../../src/server/http-handler.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,YAAY,EAAC,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,uBAAuB,CAAC;AAIvD,OAAO,KAAK,EACV,OAAO,EACP,WAAW,EACX,cAAc,EACf,MAAM,wBAAwB,CAAC;AAIhC,MAAM,WAAW,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;IACpD,MAAM,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,WAAW,CAAC,CAAC,OAAO,EAAE;QAAC,OAAO,EAAE,OAAO,CAAA;KAAC,GAAG,KAAK,CAAC;CAClD;AAED,wBAAgB,mCAAmC,CAAC,KAAK,EACvD,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,EAAC,MAAM,EAAE,WAAW,EAAC,GAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,QAAQ,GAAG,aAAa,CAAM,GACzE,cAAc,CAQhB;AAED,wBAAgB,gCAAgC,CAAC,KAAK,EACpD,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,EAAC,MAAM,EAAE,WAAW,EAAE,OAA6B,EAAC,EAAE,OAAO,CAAC,KAAK,CAAC,eAIrE;AAED,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,EAC1B,OAAO,EAAE,OAAO,EAChB,EAAC,MAAM,EAAC,GAAE;IAAC,MAAM,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAM,kEAsDlE"}
|
|
@@ -9,5 +9,5 @@ export type { HttpState } from '@quilted/react-http/server';
|
|
|
9
9
|
export { createHttpHandler } from '@quilted/http-handlers';
|
|
10
10
|
export { renderApp } from './render';
|
|
11
11
|
export { ServerContext } from './ServerContext';
|
|
12
|
-
export { createServerRenderingRequestHandler, createServerRenderingHttpHandler, } from './http-handler';
|
|
12
|
+
export { createServerRenderingRequestHandler, createServerRenderingHttpHandler, renderToResponse, } from './http-handler';
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,IAAI,EACJ,SAAS,EACT,WAAW,EACX,WAAW,EACX,gBAAgB,IAAI,qBAAqB,GAC1C,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,OAAO,GACR,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AACxD,YAAY,EACV,KAAK,EACL,WAAW,EACX,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,IAAI,6BAA6B,GAClD,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAC,gBAAgB,EAAC,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,YAAY,EAAC,SAAS,EAAC,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAC,iBAAiB,EAAC,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AACnC,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACL,mCAAmC,EACnC,gCAAgC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,IAAI,EACJ,SAAS,EACT,WAAW,EACX,WAAW,EACX,gBAAgB,IAAI,qBAAqB,GAC1C,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,OAAO,GACR,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AACxD,YAAY,EACV,KAAK,EACL,WAAW,EACX,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,IAAI,6BAA6B,GAClD,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAC,gBAAgB,EAAC,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,YAAY,EAAC,SAAS,EAAC,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAC,iBAAiB,EAAC,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AACnC,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACL,mCAAmC,EACnC,gCAAgC,EAChC,gBAAgB,GACjB,MAAM,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quilted/quilt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.67",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/lemonmade/quilt.git",
|
|
@@ -103,6 +103,12 @@
|
|
|
103
103
|
"import": "./build/esm/polyfills/base.mjs",
|
|
104
104
|
"require": "./build/cjs/polyfills/base.cjs"
|
|
105
105
|
},
|
|
106
|
+
"./polyfills/crypto": {
|
|
107
|
+
"quilt:from-source": "./src/polyfills/crypto.ts",
|
|
108
|
+
"quilt:esnext": "./build/esnext/polyfills/crypto.esnext",
|
|
109
|
+
"import": "./build/esm/polyfills/crypto.mjs",
|
|
110
|
+
"require": "./build/cjs/polyfills/crypto.cjs"
|
|
111
|
+
},
|
|
106
112
|
"./polyfills/fetch": {
|
|
107
113
|
"quilt:from-source": "./src/polyfills/fetch.ts",
|
|
108
114
|
"quilt:esnext": "./build/esnext/polyfills/fetch.esnext",
|
|
@@ -167,6 +173,9 @@
|
|
|
167
173
|
"polyfills/fetch": [
|
|
168
174
|
"./build/typescript/polyfills/fetch.d.ts"
|
|
169
175
|
],
|
|
176
|
+
"polyfills/crypto": [
|
|
177
|
+
"./build/typescript/polyfills/crypto.d.ts"
|
|
178
|
+
],
|
|
170
179
|
"polyfills/noop": [
|
|
171
180
|
"./build/typescript/polyfills/noop.d.ts"
|
|
172
181
|
],
|
package/src/html.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@quilted/polyfills/crypto';
|
|
@@ -1,84 +1,99 @@
|
|
|
1
|
-
import type {ComponentType} from 'react';
|
|
1
|
+
import type {ComponentType, ReactElement} from 'react';
|
|
2
2
|
|
|
3
3
|
import type {AssetLoader} from '@quilted/async/server';
|
|
4
|
-
import {render, Html} from '@quilted/react-html/server';
|
|
4
|
+
import {render as renderToString, Html} from '@quilted/react-html/server';
|
|
5
5
|
|
|
6
6
|
import {createHttpHandler, html, redirect} from '@quilted/http-handlers';
|
|
7
7
|
import type {
|
|
8
|
+
Request,
|
|
8
9
|
HttpHandler,
|
|
9
10
|
RequestHandler,
|
|
10
|
-
HttpHandlerOptions,
|
|
11
11
|
} from '@quilted/http-handlers';
|
|
12
12
|
|
|
13
13
|
import {renderApp} from './render';
|
|
14
14
|
|
|
15
|
-
export interface Options
|
|
16
|
-
assets
|
|
15
|
+
export interface Options<Props = Record<string, never>> {
|
|
16
|
+
assets?: AssetLoader<unknown>;
|
|
17
17
|
handler?: HttpHandler;
|
|
18
|
+
renderProps?(options: {request: Request}): Props;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
export function createServerRenderingRequestHandler(
|
|
21
|
-
App: ComponentType<
|
|
22
|
-
{assets}: Pick<Options
|
|
21
|
+
export function createServerRenderingRequestHandler<Props>(
|
|
22
|
+
App: ComponentType<Props>,
|
|
23
|
+
{assets, renderProps}: Pick<Options<Props>, 'assets' | 'renderProps'> = {},
|
|
23
24
|
): RequestHandler {
|
|
24
|
-
return
|
|
25
|
-
|
|
25
|
+
return (request) => {
|
|
26
|
+
return renderToResponse(
|
|
27
|
+
<App {...(renderProps?.({request}) as any)} />,
|
|
28
|
+
request,
|
|
29
|
+
{assets},
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
26
33
|
|
|
27
|
-
|
|
34
|
+
export function createServerRenderingHttpHandler<Props>(
|
|
35
|
+
App: ComponentType<Props>,
|
|
36
|
+
{assets, renderProps, handler = createHttpHandler()}: Options<Props>,
|
|
37
|
+
) {
|
|
38
|
+
handler.get(createServerRenderingRequestHandler(App, {assets, renderProps}));
|
|
39
|
+
return handler;
|
|
40
|
+
}
|
|
28
41
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
url: request.url,
|
|
36
|
-
headers: request.headers,
|
|
37
|
-
});
|
|
42
|
+
export async function renderToResponse(
|
|
43
|
+
element: ReactElement<any>,
|
|
44
|
+
request: Request,
|
|
45
|
+
{assets}: {assets?: AssetLoader<unknown>; request?: Request} = {},
|
|
46
|
+
) {
|
|
47
|
+
const accepts = request.headers.get('Accept');
|
|
38
48
|
|
|
39
|
-
|
|
49
|
+
if (accepts != null && !accepts.includes('text/html')) return;
|
|
40
50
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
const {
|
|
52
|
+
html: htmlManager,
|
|
53
|
+
http,
|
|
54
|
+
markup,
|
|
55
|
+
asyncAssets,
|
|
56
|
+
} = await renderApp(element, {
|
|
57
|
+
url: request.url,
|
|
58
|
+
headers: request.headers,
|
|
59
|
+
});
|
|
47
60
|
|
|
48
|
-
|
|
49
|
-
const assetOptions = {userAgent: request.headers.get('User-Agent')};
|
|
61
|
+
const {headers, statusCode = 200, redirectUrl} = http.state;
|
|
50
62
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
]);
|
|
63
|
+
if (redirectUrl) {
|
|
64
|
+
return redirect(redirectUrl, {
|
|
65
|
+
status: statusCode as 301,
|
|
66
|
+
headers,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
58
69
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
<Html
|
|
62
|
-
manager={htmlManager}
|
|
63
|
-
styles={styles}
|
|
64
|
-
scripts={scripts}
|
|
65
|
-
preloadAssets={preload}
|
|
66
|
-
>
|
|
67
|
-
{markup}
|
|
68
|
-
</Html>,
|
|
69
|
-
),
|
|
70
|
-
{
|
|
71
|
-
headers,
|
|
72
|
-
status: statusCode,
|
|
73
|
-
},
|
|
74
|
-
);
|
|
75
|
-
};
|
|
76
|
-
}
|
|
70
|
+
const usedAssets = asyncAssets.used({timing: 'load'});
|
|
71
|
+
const assetOptions = {userAgent: request.headers.get('User-Agent')};
|
|
77
72
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
const [styles, scripts, preload] = assets
|
|
74
|
+
? await Promise.all([
|
|
75
|
+
assets.styles({async: usedAssets, options: assetOptions}),
|
|
76
|
+
assets.scripts({async: usedAssets, options: assetOptions}),
|
|
77
|
+
assets.asyncAssets(asyncAssets.used({timing: 'preload'}), {
|
|
78
|
+
options: assetOptions,
|
|
79
|
+
}),
|
|
80
|
+
])
|
|
81
|
+
: [];
|
|
82
|
+
|
|
83
|
+
return html(
|
|
84
|
+
renderToString(
|
|
85
|
+
<Html
|
|
86
|
+
manager={htmlManager}
|
|
87
|
+
styles={styles}
|
|
88
|
+
scripts={scripts}
|
|
89
|
+
preloadAssets={preload}
|
|
90
|
+
>
|
|
91
|
+
{markup}
|
|
92
|
+
</Html>,
|
|
93
|
+
),
|
|
94
|
+
{
|
|
95
|
+
headers,
|
|
96
|
+
status: statusCode,
|
|
97
|
+
},
|
|
98
|
+
);
|
|
84
99
|
}
|