@quilted/quilt 0.5.66 → 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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @quilted/quilt
2
2
 
3
+ ## 0.5.67
4
+
5
+ ### Patch Changes
6
+
7
+ - [`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
8
+
3
9
  ## 0.5.66
4
10
 
5
11
  ### Patch Changes
@@ -9,62 +9,14 @@ var jsxRuntime = require('react/jsx-runtime');
9
9
 
10
10
  function createServerRenderingRequestHandler(App, {
11
11
  assets,
12
- renderProps = () => ({})
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?.({
12
+ renderProps
13
+ } = {}) {
14
+ return request => {
15
+ return renderToResponse( /*#__PURE__*/jsxRuntime.jsx(App, { ...renderProps?.({
23
16
  request
24
17
  })
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
18
+ }), request, {
19
+ assets
68
20
  });
69
21
  };
70
22
  }
@@ -79,6 +31,62 @@ function createServerRenderingHttpHandler(App, {
79
31
  }));
80
32
  return handler;
81
33
  }
34
+ async function renderToResponse(element, request, {
35
+ assets
36
+ } = {}) {
37
+ const accepts = request.headers.get('Accept');
38
+ if (accepts != null && !accepts.includes('text/html')) return;
39
+ const {
40
+ html: htmlManager,
41
+ http,
42
+ markup,
43
+ asyncAssets
44
+ } = await render.renderApp(element, {
45
+ url: request.url,
46
+ headers: request.headers
47
+ });
48
+ const {
49
+ headers,
50
+ statusCode = 200,
51
+ redirectUrl
52
+ } = http.state;
53
+
54
+ if (redirectUrl) {
55
+ return httpHandlers.redirect(redirectUrl, {
56
+ status: statusCode,
57
+ headers
58
+ });
59
+ }
60
+
61
+ const usedAssets = asyncAssets.used({
62
+ timing: 'load'
63
+ });
64
+ const assetOptions = {
65
+ userAgent: request.headers.get('User-Agent')
66
+ };
67
+ const [styles, scripts, preload] = assets ? await Promise.all([assets.styles({
68
+ async: usedAssets,
69
+ options: assetOptions
70
+ }), assets.scripts({
71
+ async: usedAssets,
72
+ options: assetOptions
73
+ }), assets.asyncAssets(asyncAssets.used({
74
+ timing: 'preload'
75
+ }), {
76
+ options: assetOptions
77
+ })]) : [];
78
+ return httpHandlers.html(server.render( /*#__PURE__*/jsxRuntime.jsx(server.Html, {
79
+ manager: htmlManager,
80
+ styles: styles,
81
+ scripts: scripts,
82
+ preloadAssets: preload,
83
+ children: markup
84
+ })), {
85
+ headers,
86
+ status: statusCode
87
+ });
88
+ }
82
89
 
83
90
  exports.createServerRenderingHttpHandler = createServerRenderingHttpHandler;
84
91
  exports.createServerRenderingRequestHandler = createServerRenderingRequestHandler;
92
+ 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,66 +1,18 @@
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
6
  function createServerRenderingRequestHandler(App, {
7
7
  assets,
8
- renderProps = () => ({})
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?.({
8
+ renderProps
9
+ } = {}) {
10
+ return request => {
11
+ return renderToResponse( /*#__PURE__*/jsx(App, { ...renderProps?.({
19
12
  request
20
13
  })
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
14
+ }), request, {
15
+ assets
64
16
  });
65
17
  };
66
18
  }
@@ -75,5 +27,60 @@ function createServerRenderingHttpHandler(App, {
75
27
  }));
76
28
  return handler;
77
29
  }
30
+ async function renderToResponse(element, request, {
31
+ assets
32
+ } = {}) {
33
+ const accepts = request.headers.get('Accept');
34
+ if (accepts != null && !accepts.includes('text/html')) return;
35
+ const {
36
+ html: htmlManager,
37
+ http,
38
+ markup,
39
+ asyncAssets
40
+ } = await renderApp(element, {
41
+ url: request.url,
42
+ headers: request.headers
43
+ });
44
+ const {
45
+ headers,
46
+ statusCode = 200,
47
+ redirectUrl
48
+ } = http.state;
49
+
50
+ if (redirectUrl) {
51
+ return redirect(redirectUrl, {
52
+ status: statusCode,
53
+ headers
54
+ });
55
+ }
56
+
57
+ const usedAssets = asyncAssets.used({
58
+ timing: 'load'
59
+ });
60
+ const assetOptions = {
61
+ userAgent: request.headers.get('User-Agent')
62
+ };
63
+ const [styles, scripts, preload] = assets ? await Promise.all([assets.styles({
64
+ async: usedAssets,
65
+ options: assetOptions
66
+ }), assets.scripts({
67
+ async: usedAssets,
68
+ options: assetOptions
69
+ }), assets.asyncAssets(asyncAssets.used({
70
+ timing: 'preload'
71
+ }), {
72
+ options: assetOptions
73
+ })]) : [];
74
+ return html(render( /*#__PURE__*/jsx(Html, {
75
+ manager: htmlManager,
76
+ styles: styles,
77
+ scripts: scripts,
78
+ preloadAssets: preload,
79
+ children: markup
80
+ })), {
81
+ headers,
82
+ status: statusCode
83
+ });
84
+ }
78
85
 
79
- export { createServerRenderingHttpHandler, createServerRenderingRequestHandler };
86
+ 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,66 +1,18 @@
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
6
  function createServerRenderingRequestHandler(App, {
7
7
  assets,
8
- renderProps = () => ({})
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?.({
8
+ renderProps
9
+ } = {}) {
10
+ return request => {
11
+ return renderToResponse( /*#__PURE__*/jsx(App, { ...renderProps?.({
19
12
  request
20
13
  })
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
14
+ }), request, {
15
+ assets
64
16
  });
65
17
  };
66
18
  }
@@ -75,5 +27,60 @@ function createServerRenderingHttpHandler(App, {
75
27
  }));
76
28
  return handler;
77
29
  }
30
+ async function renderToResponse(element, request, {
31
+ assets
32
+ } = {}) {
33
+ const accepts = request.headers.get('Accept');
34
+ if (accepts != null && !accepts.includes('text/html')) return;
35
+ const {
36
+ html: htmlManager,
37
+ http,
38
+ markup,
39
+ asyncAssets
40
+ } = await renderApp(element, {
41
+ url: request.url,
42
+ headers: request.headers
43
+ });
44
+ const {
45
+ headers,
46
+ statusCode = 200,
47
+ redirectUrl
48
+ } = http.state;
49
+
50
+ if (redirectUrl) {
51
+ return redirect(redirectUrl, {
52
+ status: statusCode,
53
+ headers
54
+ });
55
+ }
56
+
57
+ const usedAssets = asyncAssets.used({
58
+ timing: 'load'
59
+ });
60
+ const assetOptions = {
61
+ userAgent: request.headers.get('User-Agent')
62
+ };
63
+ const [styles, scripts, preload] = assets ? await Promise.all([assets.styles({
64
+ async: usedAssets,
65
+ options: assetOptions
66
+ }), assets.scripts({
67
+ async: usedAssets,
68
+ options: assetOptions
69
+ }), assets.asyncAssets(asyncAssets.used({
70
+ timing: 'preload'
71
+ }), {
72
+ options: assetOptions
73
+ })]) : [];
74
+ return html(render( /*#__PURE__*/jsx(Html, {
75
+ manager: htmlManager,
76
+ styles: styles,
77
+ scripts: scripts,
78
+ preloadAssets: preload,
79
+ children: markup
80
+ })), {
81
+ headers,
82
+ status: statusCode
83
+ });
84
+ }
78
85
 
79
- export { createServerRenderingHttpHandler, createServerRenderingRequestHandler };
86
+ 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';