@quilted/quilt 0.5.145 → 0.5.147

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,20 @@
1
1
  # @quilted/quilt
2
2
 
3
+ ## 0.5.147
4
+
5
+ ### Patch Changes
6
+
7
+ - [`93facb53`](https://github.com/lemonmade/quilt/commit/93facb530324894667817a6d2f78baea19a3b622) Thanks [@lemonmade](https://github.com/lemonmade)! - Allow omitting React element from server renderer
8
+
9
+ ## 0.5.146
10
+
11
+ ### Patch Changes
12
+
13
+ - [#582](https://github.com/lemonmade/quilt/pull/582) [`6dca6fcf`](https://github.com/lemonmade/quilt/commit/6dca6fcf62fbed7600400b619e5509c7d7f7fb45) Thanks [@lemonmade](https://github.com/lemonmade)! - Allow async module global to be lazy initialized
14
+
15
+ - Updated dependencies [[`e121e639`](https://github.com/lemonmade/quilt/commit/e121e639fb656ddf14e3e47de87d347f38edae7f)]:
16
+ - @quilted/graphql@1.1.0
17
+
3
18
  ## 0.5.145
4
19
 
5
20
  ### Patch Changes
@@ -1,5 +1,21 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  var async = require('@quilted/async');
4
6
 
5
- async.installAsyncAssetsGlobal();
7
+ const property = Symbol.for('quilt');
8
+ const quilt = globalThis[property] ?? {};
9
+ quilt.AsyncModules = async.createAsyncModulesGlobal({
10
+ cache: quilt.AsyncModules
11
+ });
12
+ Object.defineProperty(globalThis, property, {
13
+ value: quilt,
14
+ enumerable: false,
15
+ configurable: true,
16
+ writable: true
17
+ });
18
+
19
+ exports["default"] = quilt;
20
+ exports.global = quilt;
21
+ exports.quilt = quilt;
@@ -10,10 +10,16 @@ var requestRouter = require('@quilted/request-router');
10
10
  var ServerContext = require('./ServerContext.cjs');
11
11
  var jsxRuntime = require('react/jsx-runtime');
12
12
 
13
- function createServerRender(getApp, {
14
- stream,
15
- ...options
16
- } = {}) {
13
+ function createServerRender(...args) {
14
+ let getApp;
15
+ let options;
16
+ if (args.length > 1) {
17
+ getApp = args[0];
18
+ options = args[1] ?? {};
19
+ } else {
20
+ options = args[0] ?? {};
21
+ }
22
+ const stream = options.stream;
17
23
  return async (request, requestContext) => {
18
24
  const accepts = request.headers.get('Accept');
19
25
  if (accepts != null && !accepts.includes('text/html')) return;
@@ -34,7 +40,7 @@ async function renderAppToResponse(getApp, {
34
40
  context,
35
41
  assets,
36
42
  extract,
37
- renderHtml
43
+ html: htmlOptions
38
44
  }) {
39
45
  const app = typeof getApp === 'function' ? await getApp() : getApp;
40
46
  const cacheKey = await assets?.cacheKey?.(request);
@@ -59,7 +65,7 @@ async function renderAppToResponse(getApp, {
59
65
  request,
60
66
  context,
61
67
  assets,
62
- renderHtml
68
+ html: htmlOptions
63
69
  });
64
70
  return requestRouter.html(content, {
65
71
  headers,
@@ -71,7 +77,7 @@ async function renderAppToStreamedResponse(getApp, {
71
77
  context,
72
78
  assets: assets$1,
73
79
  extract,
74
- renderHtml
80
+ html: htmlOptions
75
81
  }) {
76
82
  const headers = new Headers();
77
83
  const stream = new TransformStream();
@@ -104,7 +110,7 @@ async function renderAppToStreamedResponse(getApp, {
104
110
  request,
105
111
  context,
106
112
  assets: assets$1,
107
- renderHtml
113
+ html: htmlOptions
108
114
  });
109
115
  const encoder = new TextEncoder();
110
116
  const writer = stream.writable.getWriter();
@@ -129,7 +135,7 @@ async function serverRenderDetailsForApp(app, {
129
135
  decorate,
130
136
  ...rest
131
137
  } = extractOptions ?? {};
132
- const rendered = await server$3.extract(app, {
138
+ const rendered = app ? await server$3.extract(app, {
133
139
  decorate(app) {
134
140
  return /*#__PURE__*/jsxRuntime.jsx(ServerContext.ServerContext, {
135
141
  http: http,
@@ -140,7 +146,7 @@ async function serverRenderDetailsForApp(app, {
140
146
  });
141
147
  },
142
148
  ...rest
143
- });
149
+ }) : undefined;
144
150
  return {
145
151
  rendered,
146
152
  http,
@@ -152,7 +158,7 @@ async function renderAppDetailsToHtmlString(details, {
152
158
  request,
153
159
  context,
154
160
  assets,
155
- renderHtml = defaultRenderHtml
161
+ html: htmlOptions
156
162
  }) {
157
163
  const {
158
164
  http,
@@ -172,13 +178,22 @@ async function renderAppDetailsToHtmlString(details, {
172
178
  }), {
173
179
  cacheKey
174
180
  })]) : [];
181
+ let renderHtml;
182
+ let rootElement;
183
+ if (typeof htmlOptions === 'function') {
184
+ renderHtml = htmlOptions;
185
+ } else {
186
+ rootElement = htmlOptions?.rootElement;
187
+ renderHtml = defaultRenderHtml;
188
+ }
175
189
  const htmlElement = await renderHtml(rendered, {
176
190
  request,
177
191
  context,
178
192
  html: htmlManager,
179
193
  http,
180
194
  assets: entryAssets,
181
- preloadAssets
195
+ preloadAssets,
196
+ rootElement
182
197
  });
183
198
  return server.renderHtmlToString(htmlElement);
184
199
  }
@@ -186,11 +201,13 @@ const defaultRenderHtml = function defaultRenderHtml(content, {
186
201
  request,
187
202
  html,
188
203
  assets: assets$1,
189
- preloadAssets
204
+ preloadAssets,
205
+ rootElement
190
206
  }) {
191
207
  const baseUrl = new URL(request.url);
192
208
  return /*#__PURE__*/jsxRuntime.jsx(server.Html, {
193
209
  manager: html,
210
+ rootElement: rootElement,
194
211
  headEndContent: /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
195
212
  children: [assets$1 && assets$1.styles.map(style => {
196
213
  const attributes = assets.styleAssetAttributes(style, {
@@ -1,3 +1,15 @@
1
- import { installAsyncAssetsGlobal } from '@quilted/async';
1
+ import { createAsyncModulesGlobal } from '@quilted/async';
2
2
 
3
- installAsyncAssetsGlobal();
3
+ const property = Symbol.for('quilt');
4
+ const quilt = globalThis[property] ?? {};
5
+ quilt.AsyncModules = createAsyncModulesGlobal({
6
+ cache: quilt.AsyncModules
7
+ });
8
+ Object.defineProperty(globalThis, property, {
9
+ value: quilt,
10
+ enumerable: false,
11
+ configurable: true,
12
+ writable: true
13
+ });
14
+
15
+ export { quilt as default, quilt as global, quilt };
@@ -8,10 +8,16 @@ import { redirect, html } from '@quilted/request-router';
8
8
  import { ServerContext } from './ServerContext.mjs';
9
9
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
10
10
 
11
- function createServerRender(getApp, {
12
- stream,
13
- ...options
14
- } = {}) {
11
+ function createServerRender(...args) {
12
+ let getApp;
13
+ let options;
14
+ if (args.length > 1) {
15
+ getApp = args[0];
16
+ options = args[1] ?? {};
17
+ } else {
18
+ options = args[0] ?? {};
19
+ }
20
+ const stream = options.stream;
15
21
  return async (request, requestContext) => {
16
22
  const accepts = request.headers.get('Accept');
17
23
  if (accepts != null && !accepts.includes('text/html')) return;
@@ -32,7 +38,7 @@ async function renderAppToResponse(getApp, {
32
38
  context,
33
39
  assets,
34
40
  extract,
35
- renderHtml
41
+ html: htmlOptions
36
42
  }) {
37
43
  const app = typeof getApp === 'function' ? await getApp() : getApp;
38
44
  const cacheKey = await assets?.cacheKey?.(request);
@@ -57,7 +63,7 @@ async function renderAppToResponse(getApp, {
57
63
  request,
58
64
  context,
59
65
  assets,
60
- renderHtml
66
+ html: htmlOptions
61
67
  });
62
68
  return html(content, {
63
69
  headers,
@@ -69,7 +75,7 @@ async function renderAppToStreamedResponse(getApp, {
69
75
  context,
70
76
  assets,
71
77
  extract,
72
- renderHtml
78
+ html: htmlOptions
73
79
  }) {
74
80
  const headers = new Headers();
75
81
  const stream = new TransformStream();
@@ -102,7 +108,7 @@ async function renderAppToStreamedResponse(getApp, {
102
108
  request,
103
109
  context,
104
110
  assets,
105
- renderHtml
111
+ html: htmlOptions
106
112
  });
107
113
  const encoder = new TextEncoder();
108
114
  const writer = stream.writable.getWriter();
@@ -127,7 +133,7 @@ async function serverRenderDetailsForApp(app, {
127
133
  decorate,
128
134
  ...rest
129
135
  } = extractOptions ?? {};
130
- const rendered = await extract(app, {
136
+ const rendered = app ? await extract(app, {
131
137
  decorate(app) {
132
138
  return /*#__PURE__*/jsx(ServerContext, {
133
139
  http: http,
@@ -138,7 +144,7 @@ async function serverRenderDetailsForApp(app, {
138
144
  });
139
145
  },
140
146
  ...rest
141
- });
147
+ }) : undefined;
142
148
  return {
143
149
  rendered,
144
150
  http,
@@ -150,7 +156,7 @@ async function renderAppDetailsToHtmlString(details, {
150
156
  request,
151
157
  context,
152
158
  assets,
153
- renderHtml = defaultRenderHtml
159
+ html: htmlOptions
154
160
  }) {
155
161
  const {
156
162
  http,
@@ -170,13 +176,22 @@ async function renderAppDetailsToHtmlString(details, {
170
176
  }), {
171
177
  cacheKey
172
178
  })]) : [];
179
+ let renderHtml;
180
+ let rootElement;
181
+ if (typeof htmlOptions === 'function') {
182
+ renderHtml = htmlOptions;
183
+ } else {
184
+ rootElement = htmlOptions?.rootElement;
185
+ renderHtml = defaultRenderHtml;
186
+ }
173
187
  const htmlElement = await renderHtml(rendered, {
174
188
  request,
175
189
  context,
176
190
  html: htmlManager,
177
191
  http,
178
192
  assets: entryAssets,
179
- preloadAssets
193
+ preloadAssets,
194
+ rootElement
180
195
  });
181
196
  return renderHtmlToString(htmlElement);
182
197
  }
@@ -184,11 +199,13 @@ const defaultRenderHtml = function defaultRenderHtml(content, {
184
199
  request,
185
200
  html,
186
201
  assets,
187
- preloadAssets
202
+ preloadAssets,
203
+ rootElement
188
204
  }) {
189
205
  const baseUrl = new URL(request.url);
190
206
  return /*#__PURE__*/jsx(Html, {
191
207
  manager: html,
208
+ rootElement: rootElement,
192
209
  headEndContent: /*#__PURE__*/jsxs(Fragment, {
193
210
  children: [assets && assets.styles.map(style => {
194
211
  const attributes = styleAssetAttributes(style, {
@@ -1,3 +1,15 @@
1
- import { installAsyncAssetsGlobal } from '@quilted/async';
1
+ import { createAsyncModulesGlobal } from '@quilted/async';
2
2
 
3
- installAsyncAssetsGlobal();
3
+ const property = Symbol.for('quilt');
4
+ const quilt = globalThis[property] ?? {};
5
+ quilt.AsyncModules = createAsyncModulesGlobal({
6
+ cache: quilt.AsyncModules
7
+ });
8
+ Object.defineProperty(globalThis, property, {
9
+ value: quilt,
10
+ enumerable: false,
11
+ configurable: true,
12
+ writable: true
13
+ });
14
+
15
+ export { quilt as default, quilt as global, quilt };
@@ -8,10 +8,16 @@ import { redirect, html } from '@quilted/request-router';
8
8
  import { ServerContext } from './ServerContext.esnext';
9
9
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
10
10
 
11
- function createServerRender(getApp, {
12
- stream,
13
- ...options
14
- } = {}) {
11
+ function createServerRender(...args) {
12
+ let getApp;
13
+ let options;
14
+ if (args.length > 1) {
15
+ getApp = args[0];
16
+ options = args[1] ?? {};
17
+ } else {
18
+ options = args[0] ?? {};
19
+ }
20
+ const stream = options.stream;
15
21
  return async (request, requestContext) => {
16
22
  const accepts = request.headers.get('Accept');
17
23
  if (accepts != null && !accepts.includes('text/html')) return;
@@ -32,7 +38,7 @@ async function renderAppToResponse(getApp, {
32
38
  context,
33
39
  assets,
34
40
  extract,
35
- renderHtml
41
+ html: htmlOptions
36
42
  }) {
37
43
  const app = typeof getApp === 'function' ? await getApp() : getApp;
38
44
  const cacheKey = await assets?.cacheKey?.(request);
@@ -57,7 +63,7 @@ async function renderAppToResponse(getApp, {
57
63
  request,
58
64
  context,
59
65
  assets,
60
- renderHtml
66
+ html: htmlOptions
61
67
  });
62
68
  return html(content, {
63
69
  headers,
@@ -69,7 +75,7 @@ async function renderAppToStreamedResponse(getApp, {
69
75
  context,
70
76
  assets,
71
77
  extract,
72
- renderHtml
78
+ html: htmlOptions
73
79
  }) {
74
80
  const headers = new Headers();
75
81
  const stream = new TransformStream();
@@ -102,7 +108,7 @@ async function renderAppToStreamedResponse(getApp, {
102
108
  request,
103
109
  context,
104
110
  assets,
105
- renderHtml
111
+ html: htmlOptions
106
112
  });
107
113
  const encoder = new TextEncoder();
108
114
  const writer = stream.writable.getWriter();
@@ -127,7 +133,7 @@ async function serverRenderDetailsForApp(app, {
127
133
  decorate,
128
134
  ...rest
129
135
  } = extractOptions ?? {};
130
- const rendered = await extract(app, {
136
+ const rendered = app ? await extract(app, {
131
137
  decorate(app) {
132
138
  return /*#__PURE__*/jsx(ServerContext, {
133
139
  http: http,
@@ -138,7 +144,7 @@ async function serverRenderDetailsForApp(app, {
138
144
  });
139
145
  },
140
146
  ...rest
141
- });
147
+ }) : undefined;
142
148
  return {
143
149
  rendered,
144
150
  http,
@@ -150,7 +156,7 @@ async function renderAppDetailsToHtmlString(details, {
150
156
  request,
151
157
  context,
152
158
  assets,
153
- renderHtml = defaultRenderHtml
159
+ html: htmlOptions
154
160
  }) {
155
161
  const {
156
162
  http,
@@ -170,13 +176,22 @@ async function renderAppDetailsToHtmlString(details, {
170
176
  }), {
171
177
  cacheKey
172
178
  })]) : [];
179
+ let renderHtml;
180
+ let rootElement;
181
+ if (typeof htmlOptions === 'function') {
182
+ renderHtml = htmlOptions;
183
+ } else {
184
+ rootElement = htmlOptions?.rootElement;
185
+ renderHtml = defaultRenderHtml;
186
+ }
173
187
  const htmlElement = await renderHtml(rendered, {
174
188
  request,
175
189
  context,
176
190
  html: htmlManager,
177
191
  http,
178
192
  assets: entryAssets,
179
- preloadAssets
193
+ preloadAssets,
194
+ rootElement
180
195
  });
181
196
  return renderHtmlToString(htmlElement);
182
197
  }
@@ -184,11 +199,13 @@ const defaultRenderHtml = function defaultRenderHtml(content, {
184
199
  request,
185
200
  html,
186
201
  assets,
187
- preloadAssets
202
+ preloadAssets,
203
+ rootElement
188
204
  }) {
189
205
  const baseUrl = new URL(request.url);
190
206
  return /*#__PURE__*/jsx(Html, {
191
207
  manager: html,
208
+ rootElement: rootElement,
192
209
  headEndContent: /*#__PURE__*/jsxs(Fragment, {
193
210
  children: [assets && assets.styles.map(style => {
194
211
  const attributes = styleAssetAttributes(style, {