@vue/server-renderer 3.2.47 → 3.3.0-alpha.2

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.
@@ -19,255 +19,241 @@ function _interopNamespaceDefault(e) {
19
19
 
20
20
  var Vue__namespace = /*#__PURE__*/_interopNamespaceDefault(Vue);
21
21
 
22
- // leading comma for empty string ""
23
- const shouldIgnoreProp = shared.makeMap(`,key,ref,innerHTML,textContent,ref_key,ref_for`);
22
+ const shouldIgnoreProp = shared.makeMap(
23
+ `,key,ref,innerHTML,textContent,ref_key,ref_for`
24
+ );
24
25
  function ssrRenderAttrs(props, tag) {
25
- let ret = '';
26
- for (const key in props) {
27
- if (shouldIgnoreProp(key) ||
28
- shared.isOn(key) ||
29
- (tag === 'textarea' && key === 'value')) {
30
- continue;
31
- }
32
- const value = props[key];
33
- if (key === 'class') {
34
- ret += ` class="${ssrRenderClass(value)}"`;
35
- }
36
- else if (key === 'style') {
37
- ret += ` style="${ssrRenderStyle(value)}"`;
38
- }
39
- else {
40
- ret += ssrRenderDynamicAttr(key, value, tag);
41
- }
26
+ let ret = "";
27
+ for (const key in props) {
28
+ if (shouldIgnoreProp(key) || shared.isOn(key) || tag === "textarea" && key === "value") {
29
+ continue;
30
+ }
31
+ const value = props[key];
32
+ if (key === "class") {
33
+ ret += ` class="${ssrRenderClass(value)}"`;
34
+ } else if (key === "style") {
35
+ ret += ` style="${ssrRenderStyle(value)}"`;
36
+ } else {
37
+ ret += ssrRenderDynamicAttr(key, value, tag);
42
38
  }
43
- return ret;
39
+ }
40
+ return ret;
44
41
  }
45
- // render an attr with dynamic (unknown) key.
46
42
  function ssrRenderDynamicAttr(key, value, tag) {
47
- if (!isRenderableValue(value)) {
48
- return ``;
49
- }
50
- const attrKey = tag && (tag.indexOf('-') > 0 || shared.isSVGTag(tag))
51
- ? key // preserve raw name on custom elements and svg
52
- : shared.propsToAttrMap[key] || key.toLowerCase();
53
- if (shared.isBooleanAttr(attrKey)) {
54
- return shared.includeBooleanAttr(value) ? ` ${attrKey}` : ``;
55
- }
56
- else if (shared.isSSRSafeAttrName(attrKey)) {
57
- return value === '' ? ` ${attrKey}` : ` ${attrKey}="${shared.escapeHtml(value)}"`;
58
- }
59
- else {
60
- console.warn(`[@vue/server-renderer] Skipped rendering unsafe attribute name: ${attrKey}`);
61
- return ``;
62
- }
43
+ if (!isRenderableValue(value)) {
44
+ return ``;
45
+ }
46
+ const attrKey = tag && (tag.indexOf("-") > 0 || shared.isSVGTag(tag)) ? key : shared.propsToAttrMap[key] || key.toLowerCase();
47
+ if (shared.isBooleanAttr(attrKey)) {
48
+ return shared.includeBooleanAttr(value) ? ` ${attrKey}` : ``;
49
+ } else if (shared.isSSRSafeAttrName(attrKey)) {
50
+ return value === "" ? ` ${attrKey}` : ` ${attrKey}="${shared.escapeHtml(value)}"`;
51
+ } else {
52
+ console.warn(
53
+ `[@vue/server-renderer] Skipped rendering unsafe attribute name: ${attrKey}`
54
+ );
55
+ return ``;
56
+ }
63
57
  }
64
- // Render a v-bind attr with static key. The key is pre-processed at compile
65
- // time and we only need to check and escape value.
66
58
  function ssrRenderAttr(key, value) {
67
- if (!isRenderableValue(value)) {
68
- return ``;
69
- }
70
- return ` ${key}="${shared.escapeHtml(value)}"`;
59
+ if (!isRenderableValue(value)) {
60
+ return ``;
61
+ }
62
+ return ` ${key}="${shared.escapeHtml(value)}"`;
71
63
  }
72
64
  function isRenderableValue(value) {
73
- if (value == null) {
74
- return false;
75
- }
76
- const type = typeof value;
77
- return type === 'string' || type === 'number' || type === 'boolean';
65
+ if (value == null) {
66
+ return false;
67
+ }
68
+ const type = typeof value;
69
+ return type === "string" || type === "number" || type === "boolean";
78
70
  }
79
71
  function ssrRenderClass(raw) {
80
- return shared.escapeHtml(shared.normalizeClass(raw));
72
+ return shared.escapeHtml(shared.normalizeClass(raw));
81
73
  }
82
74
  function ssrRenderStyle(raw) {
83
- if (!raw) {
84
- return '';
85
- }
86
- if (shared.isString(raw)) {
87
- return shared.escapeHtml(raw);
88
- }
89
- const styles = shared.normalizeStyle(raw);
90
- return shared.escapeHtml(shared.stringifyStyle(styles));
75
+ if (!raw) {
76
+ return "";
77
+ }
78
+ if (shared.isString(raw)) {
79
+ return shared.escapeHtml(raw);
80
+ }
81
+ const styles = shared.normalizeStyle(raw);
82
+ return shared.escapeHtml(shared.stringifyStyle(styles));
91
83
  }
92
84
 
93
85
  function ssrRenderComponent(comp, props = null, children = null, parentComponent = null, slotScopeId) {
94
- return renderComponentVNode(Vue.createVNode(comp, props, children), parentComponent, slotScopeId);
86
+ return renderComponentVNode(
87
+ Vue.createVNode(comp, props, children),
88
+ parentComponent,
89
+ slotScopeId
90
+ );
95
91
  }
96
92
 
97
93
  function ssrRenderSlot(slots, slotName, slotProps, fallbackRenderFn, push, parentComponent, slotScopeId) {
98
- // template-compiled slots are always rendered as fragments
99
- push(`<!--[-->`);
100
- ssrRenderSlotInner(slots, slotName, slotProps, fallbackRenderFn, push, parentComponent, slotScopeId);
101
- push(`<!--]-->`);
94
+ push(`<!--[-->`);
95
+ ssrRenderSlotInner(
96
+ slots,
97
+ slotName,
98
+ slotProps,
99
+ fallbackRenderFn,
100
+ push,
101
+ parentComponent,
102
+ slotScopeId
103
+ );
104
+ push(`<!--]-->`);
102
105
  }
103
106
  function ssrRenderSlotInner(slots, slotName, slotProps, fallbackRenderFn, push, parentComponent, slotScopeId, transition) {
104
- const slotFn = slots[slotName];
105
- if (slotFn) {
106
- const slotBuffer = [];
107
- const bufferedPush = (item) => {
108
- slotBuffer.push(item);
109
- };
110
- const ret = slotFn(slotProps, bufferedPush, parentComponent, slotScopeId ? ' ' + slotScopeId : '');
111
- if (shared.isArray(ret)) {
112
- // normal slot
113
- renderVNodeChildren(push, ret, parentComponent, slotScopeId);
107
+ const slotFn = slots[slotName];
108
+ if (slotFn) {
109
+ const slotBuffer = [];
110
+ const bufferedPush = (item) => {
111
+ slotBuffer.push(item);
112
+ };
113
+ const ret = slotFn(
114
+ slotProps,
115
+ bufferedPush,
116
+ parentComponent,
117
+ slotScopeId ? " " + slotScopeId : ""
118
+ );
119
+ if (shared.isArray(ret)) {
120
+ renderVNodeChildren(push, ret, parentComponent, slotScopeId);
121
+ } else {
122
+ let isEmptySlot = true;
123
+ if (transition) {
124
+ isEmptySlot = false;
125
+ } else {
126
+ for (let i = 0; i < slotBuffer.length; i++) {
127
+ if (!isComment(slotBuffer[i])) {
128
+ isEmptySlot = false;
129
+ break;
130
+ }
114
131
  }
115
- else {
116
- // ssr slot.
117
- // check if the slot renders all comments, in which case use the fallback
118
- let isEmptySlot = true;
119
- if (transition) {
120
- isEmptySlot = false;
121
- }
122
- else {
123
- for (let i = 0; i < slotBuffer.length; i++) {
124
- if (!isComment(slotBuffer[i])) {
125
- isEmptySlot = false;
126
- break;
127
- }
128
- }
129
- }
130
- if (isEmptySlot) {
131
- if (fallbackRenderFn) {
132
- fallbackRenderFn();
133
- }
134
- }
135
- else {
136
- for (let i = 0; i < slotBuffer.length; i++) {
137
- push(slotBuffer[i]);
138
- }
139
- }
132
+ }
133
+ if (isEmptySlot) {
134
+ if (fallbackRenderFn) {
135
+ fallbackRenderFn();
140
136
  }
137
+ } else {
138
+ for (let i = 0; i < slotBuffer.length; i++) {
139
+ push(slotBuffer[i]);
140
+ }
141
+ }
141
142
  }
142
- else if (fallbackRenderFn) {
143
- fallbackRenderFn();
144
- }
143
+ } else if (fallbackRenderFn) {
144
+ fallbackRenderFn();
145
+ }
145
146
  }
146
147
  const commentTestRE = /^<!--.*-->$/s;
147
148
  const commentRE = /<!--[^]*?-->/gm;
148
149
  function isComment(item) {
149
- if (typeof item !== 'string' || !commentTestRE.test(item))
150
- return false;
151
- // if item is '<!---->' or '<!--[-->' or '<!--]-->', return true directly
152
- if (item.length <= 8)
153
- return true;
154
- return !item.replace(commentRE, '').trim();
150
+ if (typeof item !== "string" || !commentTestRE.test(item))
151
+ return false;
152
+ if (item.length <= 8)
153
+ return true;
154
+ return !item.replace(commentRE, "").trim();
155
155
  }
156
156
 
157
157
  function ssrRenderTeleport(parentPush, contentRenderFn, target, disabled, parentComponent) {
158
- parentPush('<!--teleport start-->');
159
- const context = parentComponent.appContext.provides[Vue.ssrContextKey];
160
- const teleportBuffers = context.__teleportBuffers || (context.__teleportBuffers = {});
161
- const targetBuffer = teleportBuffers[target] || (teleportBuffers[target] = []);
162
- // record current index of the target buffer to handle nested teleports
163
- // since the parent needs to be rendered before the child
164
- const bufferIndex = targetBuffer.length;
165
- let teleportContent;
166
- if (disabled) {
167
- contentRenderFn(parentPush);
168
- teleportContent = `<!--teleport anchor-->`;
169
- }
170
- else {
171
- const { getBuffer, push } = createBuffer();
172
- contentRenderFn(push);
173
- push(`<!--teleport anchor-->`);
174
- teleportContent = getBuffer();
175
- }
176
- targetBuffer.splice(bufferIndex, 0, teleportContent);
177
- parentPush('<!--teleport end-->');
158
+ parentPush("<!--teleport start-->");
159
+ const context = parentComponent.appContext.provides[Vue.ssrContextKey];
160
+ const teleportBuffers = context.__teleportBuffers || (context.__teleportBuffers = {});
161
+ const targetBuffer = teleportBuffers[target] || (teleportBuffers[target] = []);
162
+ const bufferIndex = targetBuffer.length;
163
+ let teleportContent;
164
+ if (disabled) {
165
+ contentRenderFn(parentPush);
166
+ teleportContent = `<!--teleport anchor-->`;
167
+ } else {
168
+ const { getBuffer, push } = createBuffer();
169
+ contentRenderFn(push);
170
+ push(`<!--teleport anchor-->`);
171
+ teleportContent = getBuffer();
172
+ }
173
+ targetBuffer.splice(bufferIndex, 0, teleportContent);
174
+ parentPush("<!--teleport end-->");
178
175
  }
179
176
 
180
177
  function ssrInterpolate(value) {
181
- return shared.escapeHtml(shared.toDisplayString(value));
178
+ return shared.escapeHtml(shared.toDisplayString(value));
182
179
  }
183
180
 
184
181
  function ssrRenderList(source, renderItem) {
185
- if (shared.isArray(source) || shared.isString(source)) {
186
- for (let i = 0, l = source.length; i < l; i++) {
187
- renderItem(source[i], i);
188
- }
189
- }
190
- else if (typeof source === 'number') {
191
- for (let i = 0; i < source; i++) {
192
- renderItem(i + 1, i);
193
- }
194
- }
195
- else if (shared.isObject(source)) {
196
- if (source[Symbol.iterator]) {
197
- const arr = Array.from(source);
198
- for (let i = 0, l = arr.length; i < l; i++) {
199
- renderItem(arr[i], i);
200
- }
201
- }
202
- else {
203
- const keys = Object.keys(source);
204
- for (let i = 0, l = keys.length; i < l; i++) {
205
- const key = keys[i];
206
- renderItem(source[key], key, i);
207
- }
208
- }
182
+ if (shared.isArray(source) || shared.isString(source)) {
183
+ for (let i = 0, l = source.length; i < l; i++) {
184
+ renderItem(source[i], i);
185
+ }
186
+ } else if (typeof source === "number") {
187
+ for (let i = 0; i < source; i++) {
188
+ renderItem(i + 1, i);
189
+ }
190
+ } else if (shared.isObject(source)) {
191
+ if (source[Symbol.iterator]) {
192
+ const arr = Array.from(source);
193
+ for (let i = 0, l = arr.length; i < l; i++) {
194
+ renderItem(arr[i], i);
195
+ }
196
+ } else {
197
+ const keys = Object.keys(source);
198
+ for (let i = 0, l = keys.length; i < l; i++) {
199
+ const key = keys[i];
200
+ renderItem(source[key], key, i);
201
+ }
209
202
  }
203
+ }
210
204
  }
211
205
 
212
206
  async function ssrRenderSuspense(push, { default: renderContent }) {
213
- if (renderContent) {
214
- renderContent();
215
- }
216
- else {
217
- push(`<!---->`);
218
- }
207
+ if (renderContent) {
208
+ renderContent();
209
+ } else {
210
+ push(`<!---->`);
211
+ }
219
212
  }
220
213
 
221
214
  function ssrGetDirectiveProps(instance, dir, value, arg, modifiers = {}) {
222
- if (typeof dir !== 'function' && dir.getSSRProps) {
223
- return (dir.getSSRProps({
224
- dir,
225
- instance,
226
- value,
227
- oldValue: undefined,
228
- arg,
229
- modifiers
230
- }, null) || {});
231
- }
232
- return {};
215
+ if (typeof dir !== "function" && dir.getSSRProps) {
216
+ return dir.getSSRProps(
217
+ {
218
+ dir,
219
+ instance,
220
+ value,
221
+ oldValue: void 0,
222
+ arg,
223
+ modifiers
224
+ },
225
+ null
226
+ ) || {};
227
+ }
228
+ return {};
233
229
  }
234
230
 
235
231
  const ssrLooseEqual = shared.looseEqual;
236
232
  function ssrLooseContain(arr, value) {
237
- return shared.looseIndexOf(arr, value) > -1;
233
+ return shared.looseIndexOf(arr, value) > -1;
238
234
  }
239
- // for <input :type="type" v-model="model" value="value">
240
235
  function ssrRenderDynamicModel(type, model, value) {
241
- switch (type) {
242
- case 'radio':
243
- return shared.looseEqual(model, value) ? ' checked' : '';
244
- case 'checkbox':
245
- return (shared.isArray(model) ? ssrLooseContain(model, value) : model)
246
- ? ' checked'
247
- : '';
248
- default:
249
- // text types
250
- return ssrRenderAttr('value', model);
251
- }
236
+ switch (type) {
237
+ case "radio":
238
+ return shared.looseEqual(model, value) ? " checked" : "";
239
+ case "checkbox":
240
+ return (shared.isArray(model) ? ssrLooseContain(model, value) : model) ? " checked" : "";
241
+ default:
242
+ return ssrRenderAttr("value", model);
243
+ }
252
244
  }
253
- // for <input v-bind="obj" v-model="model">
254
245
  function ssrGetDynamicModelProps(existingProps = {}, model) {
255
- const { type, value } = existingProps;
256
- switch (type) {
257
- case 'radio':
258
- return shared.looseEqual(model, value) ? { checked: true } : null;
259
- case 'checkbox':
260
- return (shared.isArray(model) ? ssrLooseContain(model, value) : model)
261
- ? { checked: true }
262
- : null;
263
- default:
264
- // text types
265
- return { value: model };
266
- }
246
+ const { type, value } = existingProps;
247
+ switch (type) {
248
+ case "radio":
249
+ return shared.looseEqual(model, value) ? { checked: true } : null;
250
+ case "checkbox":
251
+ return (shared.isArray(model) ? ssrLooseContain(model, value) : model) ? { checked: true } : null;
252
+ default:
253
+ return { value: model };
254
+ }
267
255
  }
268
256
 
269
- // internal runtime helpers
270
-
271
257
  var helpers = /*#__PURE__*/Object.freeze({
272
258
  __proto__: null,
273
259
  ssrGetDirectiveProps: ssrGetDirectiveProps,
@@ -291,526 +277,523 @@ var helpers = /*#__PURE__*/Object.freeze({
291
277
  ssrRenderVNode: renderVNode
292
278
  });
293
279
 
294
- const compileCache = Object.create(null);
280
+ const compileCache = /* @__PURE__ */ Object.create(null);
295
281
  function ssrCompile(template, instance) {
296
- // TODO: This is copied from runtime-core/src/component.ts and should probably be refactored
297
- const Component = instance.type;
298
- const { isCustomElement, compilerOptions } = instance.appContext.config;
299
- const { delimiters, compilerOptions: componentCompilerOptions } = Component;
300
- const finalCompilerOptions = shared.extend(shared.extend({
282
+ const Component = instance.type;
283
+ const { isCustomElement, compilerOptions } = instance.appContext.config;
284
+ const { delimiters, compilerOptions: componentCompilerOptions } = Component;
285
+ const finalCompilerOptions = shared.extend(
286
+ shared.extend(
287
+ {
301
288
  isCustomElement,
302
289
  delimiters
303
- }, compilerOptions), componentCompilerOptions);
304
- finalCompilerOptions.isCustomElement =
305
- finalCompilerOptions.isCustomElement || shared.NO;
306
- finalCompilerOptions.isNativeTag = finalCompilerOptions.isNativeTag || shared.NO;
307
- const cacheKey = JSON.stringify({
308
- template,
309
- compilerOptions: finalCompilerOptions
310
- }, (key, value) => {
311
- return shared.isFunction(value) ? value.toString() : value;
312
- });
313
- const cached = compileCache[cacheKey];
314
- if (cached) {
315
- return cached;
316
- }
317
- finalCompilerOptions.onError = (err) => {
318
- {
319
- throw err;
320
- }
321
- };
322
- const { code } = compilerSsr.compile(template, finalCompilerOptions);
323
- const requireMap = {
324
- vue: Vue__namespace,
325
- 'vue/server-renderer': helpers
326
- };
327
- const fakeRequire = (id) => requireMap[id];
328
- return (compileCache[cacheKey] = Function('require', code)(fakeRequire));
290
+ },
291
+ compilerOptions
292
+ ),
293
+ componentCompilerOptions
294
+ );
295
+ finalCompilerOptions.isCustomElement = finalCompilerOptions.isCustomElement || shared.NO;
296
+ finalCompilerOptions.isNativeTag = finalCompilerOptions.isNativeTag || shared.NO;
297
+ const cacheKey = JSON.stringify(
298
+ {
299
+ template,
300
+ compilerOptions: finalCompilerOptions
301
+ },
302
+ (key, value) => {
303
+ return shared.isFunction(value) ? value.toString() : value;
304
+ }
305
+ );
306
+ const cached = compileCache[cacheKey];
307
+ if (cached) {
308
+ return cached;
309
+ }
310
+ finalCompilerOptions.onError = (err) => {
311
+ {
312
+ throw err;
313
+ }
314
+ };
315
+ const { code } = compilerSsr.compile(template, finalCompilerOptions);
316
+ const requireMap = {
317
+ vue: Vue__namespace,
318
+ "vue/server-renderer": helpers
319
+ };
320
+ const fakeRequire = (id) => requireMap[id];
321
+ return compileCache[cacheKey] = Function("require", code)(fakeRequire);
329
322
  }
330
323
 
331
- const { createComponentInstance, setCurrentRenderingInstance, setupComponent, renderComponentRoot, normalizeVNode } = Vue.ssrUtils;
332
- // Each component has a buffer array.
333
- // A buffer array can contain one of the following:
334
- // - plain string
335
- // - A resolved buffer (recursive arrays of strings that can be unrolled
336
- // synchronously)
337
- // - An async buffer (a Promise that resolves to a resolved buffer)
324
+ const {
325
+ createComponentInstance,
326
+ setCurrentRenderingInstance,
327
+ setupComponent,
328
+ renderComponentRoot,
329
+ normalizeVNode
330
+ } = Vue.ssrUtils;
338
331
  function createBuffer() {
339
- let appendable = false;
340
- const buffer = [];
341
- return {
342
- getBuffer() {
343
- // Return static buffer and await on items during unroll stage
344
- return buffer;
345
- },
346
- push(item) {
347
- const isStringItem = shared.isString(item);
348
- if (appendable && isStringItem) {
349
- buffer[buffer.length - 1] += item;
350
- }
351
- else {
352
- buffer.push(item);
353
- }
354
- appendable = isStringItem;
355
- if (shared.isPromise(item) || (shared.isArray(item) && item.hasAsync)) {
356
- // promise, or child buffer with async, mark as async.
357
- // this allows skipping unnecessary await ticks during unroll stage
358
- buffer.hasAsync = true;
359
- }
360
- }
361
- };
332
+ let appendable = false;
333
+ const buffer = [];
334
+ return {
335
+ getBuffer() {
336
+ return buffer;
337
+ },
338
+ push(item) {
339
+ const isStringItem = shared.isString(item);
340
+ if (appendable && isStringItem) {
341
+ buffer[buffer.length - 1] += item;
342
+ } else {
343
+ buffer.push(item);
344
+ }
345
+ appendable = isStringItem;
346
+ if (shared.isPromise(item) || shared.isArray(item) && item.hasAsync) {
347
+ buffer.hasAsync = true;
348
+ }
349
+ }
350
+ };
362
351
  }
363
352
  function renderComponentVNode(vnode, parentComponent = null, slotScopeId) {
364
- const instance = createComponentInstance(vnode, parentComponent, null);
365
- const res = setupComponent(instance, true /* isSSR */);
366
- const hasAsyncSetup = shared.isPromise(res);
367
- const prefetches = instance.sp; /* LifecycleHooks.SERVER_PREFETCH */
368
- if (hasAsyncSetup || prefetches) {
369
- let p = hasAsyncSetup
370
- ? res
371
- : Promise.resolve();
372
- if (prefetches) {
373
- p = p
374
- .then(() => Promise.all(prefetches.map(prefetch => prefetch.call(instance.proxy))))
375
- // Note: error display is already done by the wrapped lifecycle hook function.
376
- .catch(() => { });
377
- }
378
- return p.then(() => renderComponentSubTree(instance, slotScopeId));
379
- }
380
- else {
381
- return renderComponentSubTree(instance, slotScopeId);
382
- }
353
+ const instance = createComponentInstance(vnode, parentComponent, null);
354
+ const res = setupComponent(
355
+ instance,
356
+ true
357
+ /* isSSR */
358
+ );
359
+ const hasAsyncSetup = shared.isPromise(res);
360
+ const prefetches = instance.sp;
361
+ if (hasAsyncSetup || prefetches) {
362
+ let p = hasAsyncSetup ? res : Promise.resolve();
363
+ if (prefetches) {
364
+ p = p.then(
365
+ () => Promise.all(prefetches.map((prefetch) => prefetch.call(instance.proxy)))
366
+ ).catch(() => {
367
+ });
368
+ }
369
+ return p.then(() => renderComponentSubTree(instance, slotScopeId));
370
+ } else {
371
+ return renderComponentSubTree(instance, slotScopeId);
372
+ }
383
373
  }
384
374
  function renderComponentSubTree(instance, slotScopeId) {
385
- const comp = instance.type;
386
- const { getBuffer, push } = createBuffer();
387
- if (shared.isFunction(comp)) {
388
- let root = renderComponentRoot(instance);
389
- // #5817 scope ID attrs not falling through if functional component doesn't
390
- // have props
391
- if (!comp.props) {
392
- for (const key in instance.attrs) {
393
- if (key.startsWith(`data-v-`)) {
394
- (root.props || (root.props = {}))[key] = ``;
395
- }
396
- }
397
- }
398
- renderVNode(push, (instance.subTree = root), instance, slotScopeId);
375
+ const comp = instance.type;
376
+ const { getBuffer, push } = createBuffer();
377
+ if (shared.isFunction(comp)) {
378
+ let root = renderComponentRoot(instance);
379
+ if (!comp.props) {
380
+ for (const key in instance.attrs) {
381
+ if (key.startsWith(`data-v-`)) {
382
+ (root.props || (root.props = {}))[key] = ``;
383
+ }
384
+ }
385
+ }
386
+ renderVNode(push, instance.subTree = root, instance, slotScopeId);
387
+ } else {
388
+ if ((!instance.render || instance.render === shared.NOOP) && !instance.ssrRender && !comp.ssrRender && shared.isString(comp.template)) {
389
+ comp.ssrRender = ssrCompile(comp.template, instance);
390
+ }
391
+ for (const e of instance.scope.effects) {
392
+ if (e.computed)
393
+ e.computed._cacheable = true;
394
+ }
395
+ const ssrRender = instance.ssrRender || comp.ssrRender;
396
+ if (ssrRender) {
397
+ let attrs = instance.inheritAttrs !== false ? instance.attrs : void 0;
398
+ let hasCloned = false;
399
+ let cur = instance;
400
+ while (true) {
401
+ const scopeId = cur.vnode.scopeId;
402
+ if (scopeId) {
403
+ if (!hasCloned) {
404
+ attrs = { ...attrs };
405
+ hasCloned = true;
406
+ }
407
+ attrs[scopeId] = "";
408
+ }
409
+ const parent = cur.parent;
410
+ if (parent && parent.subTree && parent.subTree === cur.vnode) {
411
+ cur = parent;
412
+ } else {
413
+ break;
414
+ }
415
+ }
416
+ if (slotScopeId) {
417
+ if (!hasCloned)
418
+ attrs = { ...attrs };
419
+ attrs[slotScopeId.trim()] = "";
420
+ }
421
+ const prev = setCurrentRenderingInstance(instance);
422
+ try {
423
+ ssrRender(
424
+ instance.proxy,
425
+ push,
426
+ instance,
427
+ attrs,
428
+ // compiler-optimized bindings
429
+ instance.props,
430
+ instance.setupState,
431
+ instance.data,
432
+ instance.ctx
433
+ );
434
+ } finally {
435
+ setCurrentRenderingInstance(prev);
436
+ }
437
+ } else if (instance.render && instance.render !== shared.NOOP) {
438
+ renderVNode(
439
+ push,
440
+ instance.subTree = renderComponentRoot(instance),
441
+ instance,
442
+ slotScopeId
443
+ );
444
+ } else {
445
+ const componentName = comp.name || comp.__file || `<Anonymous>`;
446
+ Vue.warn(`Component ${componentName} is missing template or render function.`);
447
+ push(`<!---->`);
399
448
  }
400
- else {
401
- if ((!instance.render || instance.render === shared.NOOP) &&
402
- !instance.ssrRender &&
403
- !comp.ssrRender &&
404
- shared.isString(comp.template)) {
405
- comp.ssrRender = ssrCompile(comp.template, instance);
406
- }
407
- // perf: enable caching of computed getters during render
408
- // since there cannot be state mutations during render.
409
- for (const e of instance.scope.effects) {
410
- if (e.computed)
411
- e.computed._cacheable = true;
412
- }
413
- const ssrRender = instance.ssrRender || comp.ssrRender;
414
- if (ssrRender) {
415
- // optimized
416
- // resolve fallthrough attrs
417
- let attrs = instance.inheritAttrs !== false ? instance.attrs : undefined;
418
- let hasCloned = false;
419
- let cur = instance;
420
- while (true) {
421
- const scopeId = cur.vnode.scopeId;
422
- if (scopeId) {
423
- if (!hasCloned) {
424
- attrs = { ...attrs };
425
- hasCloned = true;
426
- }
427
- attrs[scopeId] = '';
428
- }
429
- const parent = cur.parent;
430
- if (parent && parent.subTree && parent.subTree === cur.vnode) {
431
- // parent is a non-SSR compiled component and is rendering this
432
- // component as root. inherit its scopeId if present.
433
- cur = parent;
434
- }
435
- else {
436
- break;
437
- }
438
- }
439
- if (slotScopeId) {
440
- if (!hasCloned)
441
- attrs = { ...attrs };
442
- attrs[slotScopeId.trim()] = '';
443
- }
444
- // set current rendering instance for asset resolution
445
- const prev = setCurrentRenderingInstance(instance);
446
- try {
447
- ssrRender(instance.proxy, push, instance, attrs,
448
- // compiler-optimized bindings
449
- instance.props, instance.setupState, instance.data, instance.ctx);
450
- }
451
- finally {
452
- setCurrentRenderingInstance(prev);
453
- }
454
- }
455
- else if (instance.render && instance.render !== shared.NOOP) {
456
- renderVNode(push, (instance.subTree = renderComponentRoot(instance)), instance, slotScopeId);
457
- }
458
- else {
459
- const componentName = comp.name || comp.__file || `<Anonymous>`;
460
- Vue.warn(`Component ${componentName} is missing template or render function.`);
461
- push(`<!---->`);
462
- }
463
- }
464
- return getBuffer();
449
+ }
450
+ return getBuffer();
465
451
  }
466
452
  function renderVNode(push, vnode, parentComponent, slotScopeId) {
467
- const { type, shapeFlag, children } = vnode;
468
- switch (type) {
469
- case Vue.Text:
470
- push(shared.escapeHtml(children));
471
- break;
472
- case Vue.Comment:
473
- push(children ? `<!--${shared.escapeHtmlComment(children)}-->` : `<!---->`);
474
- break;
475
- case Vue.Static:
476
- push(children);
477
- break;
478
- case Vue.Fragment:
479
- if (vnode.slotScopeIds) {
480
- slotScopeId =
481
- (slotScopeId ? slotScopeId + ' ' : '') + vnode.slotScopeIds.join(' ');
482
- }
483
- push(`<!--[-->`); // open
484
- renderVNodeChildren(push, children, parentComponent, slotScopeId);
485
- push(`<!--]-->`); // close
486
- break;
487
- default:
488
- if (shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
489
- renderElementVNode(push, vnode, parentComponent, slotScopeId);
490
- }
491
- else if (shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
492
- push(renderComponentVNode(vnode, parentComponent, slotScopeId));
493
- }
494
- else if (shapeFlag & 64 /* ShapeFlags.TELEPORT */) {
495
- renderTeleportVNode(push, vnode, parentComponent, slotScopeId);
496
- }
497
- else if (shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
498
- renderVNode(push, vnode.ssContent, parentComponent, slotScopeId);
499
- }
500
- else {
501
- Vue.warn('[@vue/server-renderer] Invalid VNode type:', type, `(${typeof type})`);
502
- }
503
- }
453
+ const { type, shapeFlag, children } = vnode;
454
+ switch (type) {
455
+ case Vue.Text:
456
+ push(shared.escapeHtml(children));
457
+ break;
458
+ case Vue.Comment:
459
+ push(
460
+ children ? `<!--${shared.escapeHtmlComment(children)}-->` : `<!---->`
461
+ );
462
+ break;
463
+ case Vue.Static:
464
+ push(children);
465
+ break;
466
+ case Vue.Fragment:
467
+ if (vnode.slotScopeIds) {
468
+ slotScopeId = (slotScopeId ? slotScopeId + " " : "") + vnode.slotScopeIds.join(" ");
469
+ }
470
+ push(`<!--[-->`);
471
+ renderVNodeChildren(
472
+ push,
473
+ children,
474
+ parentComponent,
475
+ slotScopeId
476
+ );
477
+ push(`<!--]-->`);
478
+ break;
479
+ default:
480
+ if (shapeFlag & 1) {
481
+ renderElementVNode(push, vnode, parentComponent, slotScopeId);
482
+ } else if (shapeFlag & 6) {
483
+ push(renderComponentVNode(vnode, parentComponent, slotScopeId));
484
+ } else if (shapeFlag & 64) {
485
+ renderTeleportVNode(push, vnode, parentComponent, slotScopeId);
486
+ } else if (shapeFlag & 128) {
487
+ renderVNode(push, vnode.ssContent, parentComponent, slotScopeId);
488
+ } else {
489
+ Vue.warn(
490
+ "[@vue/server-renderer] Invalid VNode type:",
491
+ type,
492
+ `(${typeof type})`
493
+ );
494
+ }
495
+ }
504
496
  }
505
497
  function renderVNodeChildren(push, children, parentComponent, slotScopeId) {
506
- for (let i = 0; i < children.length; i++) {
507
- renderVNode(push, normalizeVNode(children[i]), parentComponent, slotScopeId);
508
- }
498
+ for (let i = 0; i < children.length; i++) {
499
+ renderVNode(push, normalizeVNode(children[i]), parentComponent, slotScopeId);
500
+ }
509
501
  }
510
502
  function renderElementVNode(push, vnode, parentComponent, slotScopeId) {
511
- const tag = vnode.type;
512
- let { props, children, shapeFlag, scopeId, dirs } = vnode;
513
- let openTag = `<${tag}`;
514
- if (dirs) {
515
- props = applySSRDirectives(vnode, props, dirs);
516
- }
503
+ const tag = vnode.type;
504
+ let { props, children, shapeFlag, scopeId, dirs } = vnode;
505
+ let openTag = `<${tag}`;
506
+ if (dirs) {
507
+ props = applySSRDirectives(vnode, props, dirs);
508
+ }
509
+ if (props) {
510
+ openTag += ssrRenderAttrs(props, tag);
511
+ }
512
+ if (scopeId) {
513
+ openTag += ` ${scopeId}`;
514
+ }
515
+ let curParent = parentComponent;
516
+ let curVnode = vnode;
517
+ while (curParent && curVnode === curParent.subTree) {
518
+ curVnode = curParent.vnode;
519
+ if (curVnode.scopeId) {
520
+ openTag += ` ${curVnode.scopeId}`;
521
+ }
522
+ curParent = curParent.parent;
523
+ }
524
+ if (slotScopeId) {
525
+ openTag += ` ${slotScopeId}`;
526
+ }
527
+ push(openTag + `>`);
528
+ if (!shared.isVoidTag(tag)) {
529
+ let hasChildrenOverride = false;
517
530
  if (props) {
518
- openTag += ssrRenderAttrs(props, tag);
519
- }
520
- if (scopeId) {
521
- openTag += ` ${scopeId}`;
522
- }
523
- // inherit parent chain scope id if this is the root node
524
- let curParent = parentComponent;
525
- let curVnode = vnode;
526
- while (curParent && curVnode === curParent.subTree) {
527
- curVnode = curParent.vnode;
528
- if (curVnode.scopeId) {
529
- openTag += ` ${curVnode.scopeId}`;
530
- }
531
- curParent = curParent.parent;
532
- }
533
- if (slotScopeId) {
534
- openTag += ` ${slotScopeId}`;
535
- }
536
- push(openTag + `>`);
537
- if (!shared.isVoidTag(tag)) {
538
- let hasChildrenOverride = false;
539
- if (props) {
540
- if (props.innerHTML) {
541
- hasChildrenOverride = true;
542
- push(props.innerHTML);
543
- }
544
- else if (props.textContent) {
545
- hasChildrenOverride = true;
546
- push(shared.escapeHtml(props.textContent));
547
- }
548
- else if (tag === 'textarea' && props.value) {
549
- hasChildrenOverride = true;
550
- push(shared.escapeHtml(props.value));
551
- }
552
- }
553
- if (!hasChildrenOverride) {
554
- if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
555
- push(shared.escapeHtml(children));
556
- }
557
- else if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
558
- renderVNodeChildren(push, children, parentComponent, slotScopeId);
559
- }
560
- }
561
- push(`</${tag}>`);
562
- }
531
+ if (props.innerHTML) {
532
+ hasChildrenOverride = true;
533
+ push(props.innerHTML);
534
+ } else if (props.textContent) {
535
+ hasChildrenOverride = true;
536
+ push(shared.escapeHtml(props.textContent));
537
+ } else if (tag === "textarea" && props.value) {
538
+ hasChildrenOverride = true;
539
+ push(shared.escapeHtml(props.value));
540
+ }
541
+ }
542
+ if (!hasChildrenOverride) {
543
+ if (shapeFlag & 8) {
544
+ push(shared.escapeHtml(children));
545
+ } else if (shapeFlag & 16) {
546
+ renderVNodeChildren(
547
+ push,
548
+ children,
549
+ parentComponent,
550
+ slotScopeId
551
+ );
552
+ }
553
+ }
554
+ push(`</${tag}>`);
555
+ }
563
556
  }
564
557
  function applySSRDirectives(vnode, rawProps, dirs) {
565
- const toMerge = [];
566
- for (let i = 0; i < dirs.length; i++) {
567
- const binding = dirs[i];
568
- const { dir: { getSSRProps } } = binding;
569
- if (getSSRProps) {
570
- const props = getSSRProps(binding, vnode);
571
- if (props)
572
- toMerge.push(props);
573
- }
558
+ const toMerge = [];
559
+ for (let i = 0; i < dirs.length; i++) {
560
+ const binding = dirs[i];
561
+ const {
562
+ dir: { getSSRProps }
563
+ } = binding;
564
+ if (getSSRProps) {
565
+ const props = getSSRProps(binding, vnode);
566
+ if (props)
567
+ toMerge.push(props);
574
568
  }
575
- return Vue.mergeProps(rawProps || {}, ...toMerge);
569
+ }
570
+ return Vue.mergeProps(rawProps || {}, ...toMerge);
576
571
  }
577
572
  function renderTeleportVNode(push, vnode, parentComponent, slotScopeId) {
578
- const target = vnode.props && vnode.props.to;
579
- const disabled = vnode.props && vnode.props.disabled;
580
- if (!target) {
581
- if (!disabled) {
582
- Vue.warn(`[@vue/server-renderer] Teleport is missing target prop.`);
583
- }
584
- return [];
573
+ const target = vnode.props && vnode.props.to;
574
+ const disabled = vnode.props && vnode.props.disabled;
575
+ if (!target) {
576
+ if (!disabled) {
577
+ Vue.warn(`[@vue/server-renderer] Teleport is missing target prop.`);
585
578
  }
586
- if (!shared.isString(target)) {
587
- Vue.warn(`[@vue/server-renderer] Teleport target must be a query selector string.`);
588
- return [];
589
- }
590
- ssrRenderTeleport(push, push => {
591
- renderVNodeChildren(push, vnode.children, parentComponent, slotScopeId);
592
- }, target, disabled || disabled === '', parentComponent);
579
+ return [];
580
+ }
581
+ if (!shared.isString(target)) {
582
+ Vue.warn(
583
+ `[@vue/server-renderer] Teleport target must be a query selector string.`
584
+ );
585
+ return [];
586
+ }
587
+ ssrRenderTeleport(
588
+ push,
589
+ (push2) => {
590
+ renderVNodeChildren(
591
+ push2,
592
+ vnode.children,
593
+ parentComponent,
594
+ slotScopeId
595
+ );
596
+ },
597
+ target,
598
+ disabled || disabled === "",
599
+ parentComponent
600
+ );
593
601
  }
594
602
 
595
603
  const { isVNode: isVNode$1 } = Vue.ssrUtils;
596
604
  async function unrollBuffer$1(buffer) {
597
- if (buffer.hasAsync) {
598
- let ret = '';
599
- for (let i = 0; i < buffer.length; i++) {
600
- let item = buffer[i];
601
- if (shared.isPromise(item)) {
602
- item = await item;
603
- }
604
- if (shared.isString(item)) {
605
- ret += item;
606
- }
607
- else {
608
- ret += await unrollBuffer$1(item);
609
- }
610
- }
611
- return ret;
612
- }
613
- else {
614
- // sync buffer can be more efficiently unrolled without unnecessary await
615
- // ticks
616
- return unrollBufferSync$1(buffer);
605
+ if (buffer.hasAsync) {
606
+ let ret = "";
607
+ for (let i = 0; i < buffer.length; i++) {
608
+ let item = buffer[i];
609
+ if (shared.isPromise(item)) {
610
+ item = await item;
611
+ }
612
+ if (shared.isString(item)) {
613
+ ret += item;
614
+ } else {
615
+ ret += await unrollBuffer$1(item);
616
+ }
617
617
  }
618
+ return ret;
619
+ } else {
620
+ return unrollBufferSync$1(buffer);
621
+ }
618
622
  }
619
623
  function unrollBufferSync$1(buffer) {
620
- let ret = '';
621
- for (let i = 0; i < buffer.length; i++) {
622
- let item = buffer[i];
623
- if (shared.isString(item)) {
624
- ret += item;
625
- }
626
- else {
627
- // since this is a sync buffer, child buffers are never promises
628
- ret += unrollBufferSync$1(item);
629
- }
624
+ let ret = "";
625
+ for (let i = 0; i < buffer.length; i++) {
626
+ let item = buffer[i];
627
+ if (shared.isString(item)) {
628
+ ret += item;
629
+ } else {
630
+ ret += unrollBufferSync$1(item);
630
631
  }
631
- return ret;
632
+ }
633
+ return ret;
632
634
  }
633
635
  async function renderToString(input, context = {}) {
634
- if (isVNode$1(input)) {
635
- // raw vnode, wrap with app (for context)
636
- return renderToString(Vue.createApp({ render: () => input }), context);
637
- }
638
- // rendering an app
639
- const vnode = Vue.createVNode(input._component, input._props);
640
- vnode.appContext = input._context;
641
- // provide the ssr context to the tree
642
- input.provide(Vue.ssrContextKey, context);
643
- const buffer = await renderComponentVNode(vnode);
644
- const result = await unrollBuffer$1(buffer);
645
- await resolveTeleports(context);
646
- if (context.__watcherHandles) {
647
- for (const unwatch of context.__watcherHandles) {
648
- unwatch();
649
- }
636
+ if (isVNode$1(input)) {
637
+ return renderToString(Vue.createApp({ render: () => input }), context);
638
+ }
639
+ const vnode = Vue.createVNode(input._component, input._props);
640
+ vnode.appContext = input._context;
641
+ input.provide(Vue.ssrContextKey, context);
642
+ const buffer = await renderComponentVNode(vnode);
643
+ const result = await unrollBuffer$1(buffer);
644
+ await resolveTeleports(context);
645
+ if (context.__watcherHandles) {
646
+ for (const unwatch of context.__watcherHandles) {
647
+ unwatch();
650
648
  }
651
- return result;
649
+ }
650
+ return result;
652
651
  }
653
652
  async function resolveTeleports(context) {
654
- if (context.__teleportBuffers) {
655
- context.teleports = context.teleports || {};
656
- for (const key in context.__teleportBuffers) {
657
- // note: it's OK to await sequentially here because the Promises were
658
- // created eagerly in parallel.
659
- context.teleports[key] = await unrollBuffer$1(await Promise.all([context.__teleportBuffers[key]]));
660
- }
653
+ if (context.__teleportBuffers) {
654
+ context.teleports = context.teleports || {};
655
+ for (const key in context.__teleportBuffers) {
656
+ context.teleports[key] = await unrollBuffer$1(
657
+ await Promise.all([context.__teleportBuffers[key]])
658
+ );
661
659
  }
660
+ }
662
661
  }
663
662
 
664
663
  const { isVNode } = Vue.ssrUtils;
665
664
  async function unrollBuffer(buffer, stream) {
666
- if (buffer.hasAsync) {
667
- for (let i = 0; i < buffer.length; i++) {
668
- let item = buffer[i];
669
- if (shared.isPromise(item)) {
670
- item = await item;
671
- }
672
- if (shared.isString(item)) {
673
- stream.push(item);
674
- }
675
- else {
676
- await unrollBuffer(item, stream);
677
- }
678
- }
679
- }
680
- else {
681
- // sync buffer can be more efficiently unrolled without unnecessary await
682
- // ticks
683
- unrollBufferSync(buffer, stream);
684
- }
665
+ if (buffer.hasAsync) {
666
+ for (let i = 0; i < buffer.length; i++) {
667
+ let item = buffer[i];
668
+ if (shared.isPromise(item)) {
669
+ item = await item;
670
+ }
671
+ if (shared.isString(item)) {
672
+ stream.push(item);
673
+ } else {
674
+ await unrollBuffer(item, stream);
675
+ }
676
+ }
677
+ } else {
678
+ unrollBufferSync(buffer, stream);
679
+ }
685
680
  }
686
681
  function unrollBufferSync(buffer, stream) {
687
- for (let i = 0; i < buffer.length; i++) {
688
- let item = buffer[i];
689
- if (shared.isString(item)) {
690
- stream.push(item);
691
- }
692
- else {
693
- // since this is a sync buffer, child buffers are never promises
694
- unrollBufferSync(item, stream);
695
- }
682
+ for (let i = 0; i < buffer.length; i++) {
683
+ let item = buffer[i];
684
+ if (shared.isString(item)) {
685
+ stream.push(item);
686
+ } else {
687
+ unrollBufferSync(item, stream);
696
688
  }
689
+ }
697
690
  }
698
691
  function renderToSimpleStream(input, context, stream) {
699
- if (isVNode(input)) {
700
- // raw vnode, wrap with app (for context)
701
- return renderToSimpleStream(Vue.createApp({ render: () => input }), context, stream);
692
+ if (isVNode(input)) {
693
+ return renderToSimpleStream(
694
+ Vue.createApp({ render: () => input }),
695
+ context,
696
+ stream
697
+ );
698
+ }
699
+ const vnode = Vue.createVNode(input._component, input._props);
700
+ vnode.appContext = input._context;
701
+ input.provide(Vue.ssrContextKey, context);
702
+ Promise.resolve(renderComponentVNode(vnode)).then((buffer) => unrollBuffer(buffer, stream)).then(() => resolveTeleports(context)).then(() => {
703
+ if (context.__watcherHandles) {
704
+ for (const unwatch of context.__watcherHandles) {
705
+ unwatch();
706
+ }
702
707
  }
703
- // rendering an app
704
- const vnode = Vue.createVNode(input._component, input._props);
705
- vnode.appContext = input._context;
706
- // provide the ssr context to the tree
707
- input.provide(Vue.ssrContextKey, context);
708
- Promise.resolve(renderComponentVNode(vnode))
709
- .then(buffer => unrollBuffer(buffer, stream))
710
- .then(() => resolveTeleports(context))
711
- .then(() => {
712
- if (context.__watcherHandles) {
713
- for (const unwatch of context.__watcherHandles) {
714
- unwatch();
715
- }
716
- }
717
- })
718
- .then(() => stream.push(null))
719
- .catch(error => {
720
- stream.destroy(error);
721
- });
722
- return stream;
723
- }
724
- /**
725
- * @deprecated
726
- */
708
+ }).then(() => stream.push(null)).catch((error) => {
709
+ stream.destroy(error);
710
+ });
711
+ return stream;
712
+ }
727
713
  function renderToStream(input, context = {}) {
728
- console.warn(`[@vue/server-renderer] renderToStream is deprecated - use renderToNodeStream instead.`);
729
- return renderToNodeStream(input, context);
714
+ console.warn(
715
+ `[@vue/server-renderer] renderToStream is deprecated - use renderToNodeStream instead.`
716
+ );
717
+ return renderToNodeStream(input, context);
730
718
  }
731
719
  function renderToNodeStream(input, context = {}) {
732
- const stream = new (require('stream').Readable)({ read() { } })
733
- ;
734
- if (!stream) {
735
- throw new Error(`ESM build of renderToStream() does not support renderToNodeStream(). ` +
736
- `Use pipeToNodeWritable() with an existing Node.js Writable stream ` +
737
- `instance instead.`);
738
- }
739
- return renderToSimpleStream(input, context, stream);
720
+ const stream = new (require("stream")).Readable({ read() {
721
+ } }) ;
722
+ if (!stream) {
723
+ throw new Error(
724
+ `ESM build of renderToStream() does not support renderToNodeStream(). Use pipeToNodeWritable() with an existing Node.js Writable stream instance instead.`
725
+ );
726
+ }
727
+ return renderToSimpleStream(input, context, stream);
740
728
  }
741
729
  function pipeToNodeWritable(input, context = {}, writable) {
742
- renderToSimpleStream(input, context, {
730
+ renderToSimpleStream(input, context, {
731
+ push(content) {
732
+ if (content != null) {
733
+ writable.write(content);
734
+ } else {
735
+ writable.end();
736
+ }
737
+ },
738
+ destroy(err) {
739
+ writable.destroy(err);
740
+ }
741
+ });
742
+ }
743
+ function renderToWebStream(input, context = {}) {
744
+ if (typeof ReadableStream !== "function") {
745
+ throw new Error(
746
+ `ReadableStream constructor is not available in the global scope. If the target environment does support web streams, consider using pipeToWebWritable() with an existing WritableStream instance instead.`
747
+ );
748
+ }
749
+ const encoder = new TextEncoder();
750
+ let cancelled = false;
751
+ return new ReadableStream({
752
+ start(controller) {
753
+ renderToSimpleStream(input, context, {
743
754
  push(content) {
744
- if (content != null) {
745
- writable.write(content);
746
- }
747
- else {
748
- writable.end();
749
- }
755
+ if (cancelled)
756
+ return;
757
+ if (content != null) {
758
+ controller.enqueue(encoder.encode(content));
759
+ } else {
760
+ controller.close();
761
+ }
750
762
  },
751
763
  destroy(err) {
752
- writable.destroy(err);
764
+ controller.error(err);
753
765
  }
754
- });
755
- }
756
- function renderToWebStream(input, context = {}) {
757
- if (typeof ReadableStream !== 'function') {
758
- throw new Error(`ReadableStream constructor is not available in the global scope. ` +
759
- `If the target environment does support web streams, consider using ` +
760
- `pipeToWebWritable() with an existing WritableStream instance instead.`);
766
+ });
767
+ },
768
+ cancel() {
769
+ cancelled = true;
761
770
  }
762
- const encoder = new TextEncoder();
763
- let cancelled = false;
764
- return new ReadableStream({
765
- start(controller) {
766
- renderToSimpleStream(input, context, {
767
- push(content) {
768
- if (cancelled)
769
- return;
770
- if (content != null) {
771
- controller.enqueue(encoder.encode(content));
772
- }
773
- else {
774
- controller.close();
775
- }
776
- },
777
- destroy(err) {
778
- controller.error(err);
779
- }
780
- });
781
- },
782
- cancel() {
783
- cancelled = true;
784
- }
785
- });
771
+ });
786
772
  }
787
773
  function pipeToWebWritable(input, context = {}, writable) {
788
- const writer = writable.getWriter();
789
- const encoder = new TextEncoder();
790
- // #4287 CloudFlare workers do not implement `ready` property
791
- let hasReady = false;
792
- try {
793
- hasReady = shared.isPromise(writer.ready);
794
- }
795
- catch (e) { }
796
- renderToSimpleStream(input, context, {
797
- async push(content) {
798
- if (hasReady) {
799
- await writer.ready;
800
- }
801
- if (content != null) {
802
- return writer.write(encoder.encode(content));
803
- }
804
- else {
805
- return writer.close();
806
- }
807
- },
808
- destroy(err) {
809
- // TODO better error handling?
810
- console.log(err);
811
- writer.close();
812
- }
813
- });
774
+ const writer = writable.getWriter();
775
+ const encoder = new TextEncoder();
776
+ let hasReady = false;
777
+ try {
778
+ hasReady = shared.isPromise(writer.ready);
779
+ } catch (e) {
780
+ }
781
+ renderToSimpleStream(input, context, {
782
+ async push(content) {
783
+ if (hasReady) {
784
+ await writer.ready;
785
+ }
786
+ if (content != null) {
787
+ return writer.write(encoder.encode(content));
788
+ } else {
789
+ return writer.close();
790
+ }
791
+ },
792
+ destroy(err) {
793
+ console.log(err);
794
+ writer.close();
795
+ }
796
+ });
814
797
  }
815
798
 
816
799
  Vue.initDirectivesForSSR();