@quilted/quilt 0.5.65 → 0.5.68

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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @quilted/quilt
2
2
 
3
+ ## 0.5.68
4
+
5
+ ### Patch Changes
6
+
7
+ - [`c4c6792`](https://github.com/lemonmade/quilt/commit/c4c6792ef355cc3bc8c8ada65ec7b1db8a836fef) Thanks [@lemonmade](https://github.com/lemonmade)! - Improve server rendering helpers
8
+
9
+ ## 0.5.67
10
+
11
+ ### Patch Changes
12
+
13
+ - [`ec90a3f`](https://github.com/lemonmade/quilt/commit/ec90a3f0de7366a42fd1e13b903154f5bc8c0a54) Thanks [@lemonmade](https://github.com/lemonmade)! - Add simpler way of rendering React to a http-handlers response
14
+
15
+ ## 0.5.66
16
+
17
+ ### Patch Changes
18
+
19
+ - [`fb10e01`](https://github.com/lemonmade/quilt/commit/fb10e0181c26b6faedaea6f7fc5d88d7ccccc3d1) Thanks [@lemonmade](https://github.com/lemonmade)! - Add web crypto polyfill
20
+
21
+ * [`33c1a59`](https://github.com/lemonmade/quilt/commit/33c1a59c89fd9aeae81cb6072b4100d706268985) Thanks [@lemonmade](https://github.com/lemonmade)! - Add ability to nest http handlers
22
+
3
23
  ## 0.5.65
4
24
 
5
25
  ### Patch Changes
@@ -7,81 +7,81 @@ var httpHandlers = require('@quilted/http-handlers');
7
7
  var render = require('./render.cjs');
8
8
  var jsxRuntime = require('react/jsx-runtime');
9
9
 
10
- function createServerRenderingRequestHandler(App, {
11
- assets,
12
- renderProps = () => ({})
10
+ function createServerRenderingHttpHandler(App, {
11
+ handler = httpHandlers.createHttpHandler(),
12
+ ...options
13
13
  }) {
14
- return async request => {
15
- const accepts = request.headers.get('Accept');
16
- if (accepts != null && !accepts.includes('text/html')) return;
17
- const {
18
- html: htmlManager,
19
- http,
20
- markup,
21
- asyncAssets
22
- } = await render.renderApp( /*#__PURE__*/jsxRuntime.jsx(App, { ...renderProps?.({
14
+ handler.get(createServerRenderingRequestHandler(App, options));
15
+ return handler;
16
+ }
17
+ function createServerRenderingRequestHandler(App, {
18
+ renderProps,
19
+ ...options
20
+ } = {}) {
21
+ return request => {
22
+ return renderToResponse( /*#__PURE__*/jsxRuntime.jsx(App, { ...renderProps?.({
23
23
  request
24
24
  })
25
- }), {
26
- url: request.url,
27
- headers: request.headers
28
- });
29
- const {
30
- headers,
31
- statusCode = 200,
32
- redirectUrl
33
- } = http.state;
34
-
35
- if (redirectUrl) {
36
- return httpHandlers.redirect(redirectUrl, {
37
- status: statusCode,
38
- headers
39
- });
40
- }
41
-
42
- const usedAssets = asyncAssets.used({
43
- timing: 'load'
44
- });
45
- const assetOptions = {
46
- userAgent: request.headers.get('User-Agent')
47
- };
48
- const [styles, scripts, preload] = await Promise.all([assets.styles({
49
- async: usedAssets,
50
- options: assetOptions
51
- }), assets.scripts({
52
- async: usedAssets,
53
- options: assetOptions
54
- }), assets.asyncAssets(asyncAssets.used({
55
- timing: 'preload'
56
- }), {
57
- options: assetOptions
58
- })]);
59
- return httpHandlers.html(server.render( /*#__PURE__*/jsxRuntime.jsx(server.Html, {
60
- manager: htmlManager,
61
- styles: styles,
62
- scripts: scripts,
63
- preloadAssets: preload,
64
- children: markup
65
- })), {
66
- headers,
67
- status: statusCode
68
- });
25
+ }), request, options);
69
26
  };
70
27
  }
71
- function createServerRenderingHttpHandler(App, {
28
+ async function renderToResponse(element, request, {
72
29
  assets,
73
- before,
74
- renderProps,
75
- handler = httpHandlers.createHttpHandler({
76
- before
77
- })
78
- }) {
79
- handler.get(createServerRenderingRequestHandler(App, {
80
- assets,
81
- renderProps
82
- }));
83
- return handler;
30
+ ...options
31
+ } = {}) {
32
+ const accepts = request.headers.get('Accept');
33
+ if (accepts != null && !accepts.includes('text/html')) return;
34
+ const {
35
+ html: htmlManager,
36
+ http,
37
+ markup,
38
+ asyncAssets
39
+ } = await render.renderApp(element, { ...options,
40
+ url: request.url,
41
+ headers: request.headers
42
+ });
43
+ const {
44
+ headers,
45
+ statusCode = 200,
46
+ redirectUrl
47
+ } = http.state;
48
+
49
+ if (redirectUrl) {
50
+ return httpHandlers.redirect(redirectUrl, {
51
+ status: statusCode,
52
+ headers
53
+ });
54
+ }
55
+
56
+ const usedAssets = asyncAssets.used({
57
+ timing: 'load'
58
+ });
59
+ const assetOptions = {
60
+ userAgent: request.headers.get('User-Agent')
61
+ };
62
+ const [styles, scripts, preload] = assets ? await Promise.all([assets.styles({
63
+ async: usedAssets,
64
+ options: assetOptions
65
+ }), assets.scripts({
66
+ async: usedAssets,
67
+ options: assetOptions
68
+ }), assets.asyncAssets(asyncAssets.used({
69
+ timing: 'preload'
70
+ }), {
71
+ options: assetOptions
72
+ })]) : [];
73
+ return httpHandlers.html(server.render( /*#__PURE__*/jsxRuntime.jsx(server.Html, {
74
+ manager: htmlManager,
75
+ styles: styles,
76
+ scripts: scripts,
77
+ preloadAssets: preload,
78
+ children: markup
79
+ })), {
80
+ headers,
81
+ status: statusCode
82
+ });
84
83
  }
85
84
 
86
85
  exports.createServerRenderingHttpHandler = createServerRenderingHttpHandler;
87
86
  exports.createServerRenderingRequestHandler = createServerRenderingRequestHandler;
87
+ exports.renderToResponse = renderToResponse;
@@ -86,3 +86,4 @@ exports.renderApp = render.renderApp;
86
86
  exports.ServerContext = ServerContext.ServerContext;
87
87
  exports.createServerRenderingHttpHandler = httpHandler.createServerRenderingHttpHandler;
88
88
  exports.createServerRenderingRequestHandler = httpHandler.createServerRenderingRequestHandler;
89
+ exports.renderToResponse = httpHandler.renderToResponse;
@@ -1,82 +1,81 @@
1
1
  import { render, Html } from '@quilted/react-html/server';
2
- import { redirect, html, createHttpHandler } from '@quilted/http-handlers';
2
+ import { createHttpHandler, redirect, html } from '@quilted/http-handlers';
3
3
  import { renderApp } from './render.mjs';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5
 
6
- function createServerRenderingRequestHandler(App, {
7
- assets,
8
- renderProps = () => ({})
6
+ function createServerRenderingHttpHandler(App, {
7
+ handler = createHttpHandler(),
8
+ ...options
9
9
  }) {
10
- return async request => {
11
- const accepts = request.headers.get('Accept');
12
- if (accepts != null && !accepts.includes('text/html')) return;
13
- const {
14
- html: htmlManager,
15
- http,
16
- markup,
17
- asyncAssets
18
- } = await renderApp( /*#__PURE__*/jsx(App, { ...renderProps?.({
10
+ handler.get(createServerRenderingRequestHandler(App, options));
11
+ return handler;
12
+ }
13
+ function createServerRenderingRequestHandler(App, {
14
+ renderProps,
15
+ ...options
16
+ } = {}) {
17
+ return request => {
18
+ return renderToResponse( /*#__PURE__*/jsx(App, { ...renderProps?.({
19
19
  request
20
20
  })
21
- }), {
22
- url: request.url,
23
- headers: request.headers
24
- });
25
- const {
26
- headers,
27
- statusCode = 200,
28
- redirectUrl
29
- } = http.state;
30
-
31
- if (redirectUrl) {
32
- return redirect(redirectUrl, {
33
- status: statusCode,
34
- headers
35
- });
36
- }
37
-
38
- const usedAssets = asyncAssets.used({
39
- timing: 'load'
40
- });
41
- const assetOptions = {
42
- userAgent: request.headers.get('User-Agent')
43
- };
44
- const [styles, scripts, preload] = await Promise.all([assets.styles({
45
- async: usedAssets,
46
- options: assetOptions
47
- }), assets.scripts({
48
- async: usedAssets,
49
- options: assetOptions
50
- }), assets.asyncAssets(asyncAssets.used({
51
- timing: 'preload'
52
- }), {
53
- options: assetOptions
54
- })]);
55
- return html(render( /*#__PURE__*/jsx(Html, {
56
- manager: htmlManager,
57
- styles: styles,
58
- scripts: scripts,
59
- preloadAssets: preload,
60
- children: markup
61
- })), {
62
- headers,
63
- status: statusCode
64
- });
21
+ }), request, options);
65
22
  };
66
23
  }
67
- function createServerRenderingHttpHandler(App, {
24
+ async function renderToResponse(element, request, {
68
25
  assets,
69
- before,
70
- renderProps,
71
- handler = createHttpHandler({
72
- before
73
- })
74
- }) {
75
- handler.get(createServerRenderingRequestHandler(App, {
76
- assets,
77
- renderProps
78
- }));
79
- return handler;
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(element, { ...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
+ manager: htmlManager,
71
+ styles: styles,
72
+ scripts: scripts,
73
+ preloadAssets: preload,
74
+ children: markup
75
+ })), {
76
+ headers,
77
+ status: statusCode
78
+ });
80
79
  }
81
80
 
82
- export { createServerRenderingHttpHandler, createServerRenderingRequestHandler };
81
+ export { createServerRenderingHttpHandler, createServerRenderingRequestHandler, renderToResponse };
@@ -6,4 +6,4 @@ export { renderEmail } from '@quilted/react-email/server';
6
6
  export { createHttpHandler } from '@quilted/http-handlers';
7
7
  export { renderApp } from './render.mjs';
8
8
  export { ServerContext } from './ServerContext.mjs';
9
- export { createServerRenderingHttpHandler, createServerRenderingRequestHandler } from './http-handler.mjs';
9
+ export { createServerRenderingHttpHandler, createServerRenderingRequestHandler, renderToResponse } from './http-handler.mjs';
@@ -1,82 +1,81 @@
1
1
  import { render, Html } from '@quilted/react-html/server';
2
- import { redirect, html, createHttpHandler } from '@quilted/http-handlers';
2
+ import { createHttpHandler, redirect, html } from '@quilted/http-handlers';
3
3
  import { renderApp } from './render.esnext';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5
 
6
- function createServerRenderingRequestHandler(App, {
7
- assets,
8
- renderProps = () => ({})
6
+ function createServerRenderingHttpHandler(App, {
7
+ handler = createHttpHandler(),
8
+ ...options
9
9
  }) {
10
- return async request => {
11
- const accepts = request.headers.get('Accept');
12
- if (accepts != null && !accepts.includes('text/html')) return;
13
- const {
14
- html: htmlManager,
15
- http,
16
- markup,
17
- asyncAssets
18
- } = await renderApp( /*#__PURE__*/jsx(App, { ...renderProps?.({
10
+ handler.get(createServerRenderingRequestHandler(App, options));
11
+ return handler;
12
+ }
13
+ function createServerRenderingRequestHandler(App, {
14
+ renderProps,
15
+ ...options
16
+ } = {}) {
17
+ return request => {
18
+ return renderToResponse( /*#__PURE__*/jsx(App, { ...renderProps?.({
19
19
  request
20
20
  })
21
- }), {
22
- url: request.url,
23
- headers: request.headers
24
- });
25
- const {
26
- headers,
27
- statusCode = 200,
28
- redirectUrl
29
- } = http.state;
30
-
31
- if (redirectUrl) {
32
- return redirect(redirectUrl, {
33
- status: statusCode,
34
- headers
35
- });
36
- }
37
-
38
- const usedAssets = asyncAssets.used({
39
- timing: 'load'
40
- });
41
- const assetOptions = {
42
- userAgent: request.headers.get('User-Agent')
43
- };
44
- const [styles, scripts, preload] = await Promise.all([assets.styles({
45
- async: usedAssets,
46
- options: assetOptions
47
- }), assets.scripts({
48
- async: usedAssets,
49
- options: assetOptions
50
- }), assets.asyncAssets(asyncAssets.used({
51
- timing: 'preload'
52
- }), {
53
- options: assetOptions
54
- })]);
55
- return html(render( /*#__PURE__*/jsx(Html, {
56
- manager: htmlManager,
57
- styles: styles,
58
- scripts: scripts,
59
- preloadAssets: preload,
60
- children: markup
61
- })), {
62
- headers,
63
- status: statusCode
64
- });
21
+ }), request, options);
65
22
  };
66
23
  }
67
- function createServerRenderingHttpHandler(App, {
24
+ async function renderToResponse(element, request, {
68
25
  assets,
69
- before,
70
- renderProps,
71
- handler = createHttpHandler({
72
- before
73
- })
74
- }) {
75
- handler.get(createServerRenderingRequestHandler(App, {
76
- assets,
77
- renderProps
78
- }));
79
- return handler;
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(element, { ...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
+ manager: htmlManager,
71
+ styles: styles,
72
+ scripts: scripts,
73
+ preloadAssets: preload,
74
+ children: markup
75
+ })), {
76
+ headers,
77
+ status: statusCode
78
+ });
80
79
  }
81
80
 
82
- export { createServerRenderingHttpHandler, createServerRenderingRequestHandler };
81
+ export { createServerRenderingHttpHandler, createServerRenderingRequestHandler, renderToResponse };
@@ -6,4 +6,4 @@ export { renderEmail } from '@quilted/react-email/server';
6
6
  export { createHttpHandler } from '@quilted/http-handlers';
7
7
  export { renderApp } from './render.esnext';
8
8
  export { ServerContext } from './ServerContext.esnext';
9
- export { createServerRenderingHttpHandler, createServerRenderingRequestHandler } from './http-handler.esnext';
9
+ export { createServerRenderingHttpHandler, createServerRenderingRequestHandler, renderToResponse } from './http-handler.esnext';