@vue/server-renderer 3.2.46 → 3.3.0-alpha.1
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/dist/server-renderer.cjs.js +838 -864
- package/dist/server-renderer.cjs.prod.js +641 -656
- package/dist/server-renderer.d.ts +71 -101
- package/dist/server-renderer.esm-browser.js +6724 -7333
- package/dist/server-renderer.esm-browser.prod.js +1 -1
- package/dist/server-renderer.esm-bundler.js +812 -852
- package/package.json +4 -4
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
3
5
|
var Vue = require('vue');
|
|
4
6
|
var shared = require('@vue/shared');
|
|
5
7
|
var compilerSsr = require('@vue/compiler-ssr');
|
|
@@ -17,515 +19,486 @@ function _interopNamespaceDefault(e) {
|
|
|
17
19
|
|
|
18
20
|
var Vue__namespace = /*#__PURE__*/_interopNamespaceDefault(Vue);
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
const shouldIgnoreProp = shared.makeMap(
|
|
23
|
+
`,key,ref,innerHTML,textContent,ref_key,ref_for`
|
|
24
|
+
);
|
|
22
25
|
function ssrRenderAttrs(props, tag) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
ret += ` style="${ssrRenderStyle(value)}"`;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
ret += ssrRenderDynamicAttr(key, value, tag);
|
|
39
|
-
}
|
|
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);
|
|
40
38
|
}
|
|
41
|
-
|
|
39
|
+
}
|
|
40
|
+
return ret;
|
|
42
41
|
}
|
|
43
|
-
// render an attr with dynamic (unknown) key.
|
|
44
42
|
function ssrRenderDynamicAttr(key, value, tag) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return ``;
|
|
60
|
-
}
|
|
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
|
+
}
|
|
61
57
|
}
|
|
62
|
-
// Render a v-bind attr with static key. The key is pre-processed at compile
|
|
63
|
-
// time and we only need to check and escape value.
|
|
64
58
|
function ssrRenderAttr(key, value) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
if (!isRenderableValue(value)) {
|
|
60
|
+
return ``;
|
|
61
|
+
}
|
|
62
|
+
return ` ${key}="${shared.escapeHtml(value)}"`;
|
|
69
63
|
}
|
|
70
64
|
function isRenderableValue(value) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
if (value == null) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const type = typeof value;
|
|
69
|
+
return type === "string" || type === "number" || type === "boolean";
|
|
76
70
|
}
|
|
77
71
|
function ssrRenderClass(raw) {
|
|
78
|
-
|
|
72
|
+
return shared.escapeHtml(shared.normalizeClass(raw));
|
|
79
73
|
}
|
|
80
74
|
function ssrRenderStyle(raw) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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));
|
|
89
83
|
}
|
|
90
84
|
|
|
91
85
|
function ssrRenderComponent(comp, props = null, children = null, parentComponent = null, slotScopeId) {
|
|
92
|
-
|
|
86
|
+
return renderComponentVNode(
|
|
87
|
+
Vue.createVNode(comp, props, children),
|
|
88
|
+
parentComponent,
|
|
89
|
+
slotScopeId
|
|
90
|
+
);
|
|
93
91
|
}
|
|
94
92
|
|
|
95
93
|
function ssrRenderSlot(slots, slotName, slotProps, fallbackRenderFn, push, parentComponent, slotScopeId) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
94
|
+
push(`<!--[-->`);
|
|
95
|
+
ssrRenderSlotInner(
|
|
96
|
+
slots,
|
|
97
|
+
slotName,
|
|
98
|
+
slotProps,
|
|
99
|
+
fallbackRenderFn,
|
|
100
|
+
push,
|
|
101
|
+
parentComponent,
|
|
102
|
+
slotScopeId
|
|
103
|
+
);
|
|
104
|
+
push(`<!--]-->`);
|
|
100
105
|
}
|
|
101
106
|
function ssrRenderSlotInner(slots, slotName, slotProps, fallbackRenderFn, push, parentComponent, slotScopeId, transition) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
+
}
|
|
112
131
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (transition) {
|
|
118
|
-
isEmptySlot = false;
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
for (let i = 0; i < slotBuffer.length; i++) {
|
|
122
|
-
if (!isComment(slotBuffer[i])) {
|
|
123
|
-
isEmptySlot = false;
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (isEmptySlot) {
|
|
129
|
-
if (fallbackRenderFn) {
|
|
130
|
-
fallbackRenderFn();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
for (let i = 0; i < slotBuffer.length; i++) {
|
|
135
|
-
push(slotBuffer[i]);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
132
|
+
}
|
|
133
|
+
if (isEmptySlot) {
|
|
134
|
+
if (fallbackRenderFn) {
|
|
135
|
+
fallbackRenderFn();
|
|
138
136
|
}
|
|
137
|
+
} else {
|
|
138
|
+
for (let i = 0; i < slotBuffer.length; i++) {
|
|
139
|
+
push(slotBuffer[i]);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
139
142
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
} else if (fallbackRenderFn) {
|
|
144
|
+
fallbackRenderFn();
|
|
145
|
+
}
|
|
143
146
|
}
|
|
144
147
|
const commentTestRE = /^<!--.*-->$/s;
|
|
145
148
|
const commentRE = /<!--[^]*?-->/gm;
|
|
146
149
|
function isComment(item) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
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();
|
|
153
155
|
}
|
|
154
156
|
|
|
155
157
|
function ssrRenderTeleport(parentPush, contentRenderFn, target, disabled, parentComponent) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
targetBuffer.splice(bufferIndex, 0, teleportContent);
|
|
175
|
-
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-->");
|
|
176
175
|
}
|
|
177
176
|
|
|
178
177
|
function ssrInterpolate(value) {
|
|
179
|
-
|
|
178
|
+
return shared.escapeHtml(shared.toDisplayString(value));
|
|
180
179
|
}
|
|
181
180
|
|
|
182
181
|
let shouldTrack = true;
|
|
183
182
|
const trackStack = [];
|
|
184
183
|
function pauseTracking() {
|
|
185
|
-
|
|
186
|
-
|
|
184
|
+
trackStack.push(shouldTrack);
|
|
185
|
+
shouldTrack = false;
|
|
187
186
|
}
|
|
188
187
|
function resetTracking() {
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
const last = trackStack.pop();
|
|
189
|
+
shouldTrack = last === void 0 ? true : last;
|
|
191
190
|
}
|
|
192
191
|
|
|
193
192
|
function toRaw(observed) {
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
const raw = observed && observed["__v_raw"];
|
|
194
|
+
return raw ? toRaw(raw) : observed;
|
|
196
195
|
}
|
|
197
196
|
|
|
198
197
|
function isRef(r) {
|
|
199
|
-
|
|
198
|
+
return !!(r && r.__v_isRef === true);
|
|
200
199
|
}
|
|
201
200
|
|
|
202
201
|
const stack = [];
|
|
203
202
|
function pushWarningContext(vnode) {
|
|
204
|
-
|
|
203
|
+
stack.push(vnode);
|
|
205
204
|
}
|
|
206
205
|
function popWarningContext() {
|
|
207
|
-
|
|
206
|
+
stack.pop();
|
|
208
207
|
}
|
|
209
208
|
function warn(msg, ...args) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
209
|
+
pauseTracking();
|
|
210
|
+
const instance = stack.length ? stack[stack.length - 1].component : null;
|
|
211
|
+
const appWarnHandler = instance && instance.appContext.config.warnHandler;
|
|
212
|
+
const trace = getComponentTrace();
|
|
213
|
+
if (appWarnHandler) {
|
|
214
|
+
callWithErrorHandling(
|
|
215
|
+
appWarnHandler,
|
|
216
|
+
instance,
|
|
217
|
+
11,
|
|
218
|
+
[
|
|
219
|
+
msg + args.join(""),
|
|
220
|
+
instance && instance.proxy,
|
|
221
|
+
trace.map(
|
|
222
|
+
({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`
|
|
223
|
+
).join("\n"),
|
|
224
|
+
trace
|
|
225
|
+
]
|
|
226
|
+
);
|
|
227
|
+
} else {
|
|
228
|
+
const warnArgs = [`[Vue warn]: ${msg}`, ...args];
|
|
229
|
+
if (trace.length && // avoid spamming console during tests
|
|
230
|
+
true) {
|
|
231
|
+
warnArgs.push(`
|
|
232
|
+
`, ...formatTrace(trace));
|
|
233
|
+
}
|
|
234
|
+
console.warn(...warnArgs);
|
|
235
|
+
}
|
|
236
|
+
resetTracking();
|
|
237
237
|
}
|
|
238
238
|
function getComponentTrace() {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const parentInstance = currentVNode.component && currentVNode.component.parent;
|
|
259
|
-
currentVNode = parentInstance && parentInstance.vnode;
|
|
260
|
-
}
|
|
261
|
-
return normalizedStack;
|
|
239
|
+
let currentVNode = stack[stack.length - 1];
|
|
240
|
+
if (!currentVNode) {
|
|
241
|
+
return [];
|
|
242
|
+
}
|
|
243
|
+
const normalizedStack = [];
|
|
244
|
+
while (currentVNode) {
|
|
245
|
+
const last = normalizedStack[0];
|
|
246
|
+
if (last && last.vnode === currentVNode) {
|
|
247
|
+
last.recurseCount++;
|
|
248
|
+
} else {
|
|
249
|
+
normalizedStack.push({
|
|
250
|
+
vnode: currentVNode,
|
|
251
|
+
recurseCount: 0
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
const parentInstance = currentVNode.component && currentVNode.component.parent;
|
|
255
|
+
currentVNode = parentInstance && parentInstance.vnode;
|
|
256
|
+
}
|
|
257
|
+
return normalizedStack;
|
|
262
258
|
}
|
|
263
|
-
/* istanbul ignore next */
|
|
264
259
|
function formatTrace(trace) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
260
|
+
const logs = [];
|
|
261
|
+
trace.forEach((entry, i) => {
|
|
262
|
+
logs.push(...i === 0 ? [] : [`
|
|
263
|
+
`], ...formatTraceEntry(entry));
|
|
264
|
+
});
|
|
265
|
+
return logs;
|
|
270
266
|
}
|
|
271
267
|
function formatTraceEntry({ vnode, recurseCount }) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
268
|
+
const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
|
|
269
|
+
const isRoot = vnode.component ? vnode.component.parent == null : false;
|
|
270
|
+
const open = ` at <${formatComponentName(
|
|
271
|
+
vnode.component,
|
|
272
|
+
vnode.type,
|
|
273
|
+
isRoot
|
|
274
|
+
)}`;
|
|
275
|
+
const close = `>` + postfix;
|
|
276
|
+
return vnode.props ? [open, ...formatProps(vnode.props), close] : [open + close];
|
|
279
277
|
}
|
|
280
|
-
/* istanbul ignore next */
|
|
281
278
|
function formatProps(props) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
279
|
+
const res = [];
|
|
280
|
+
const keys = Object.keys(props);
|
|
281
|
+
keys.slice(0, 3).forEach((key) => {
|
|
282
|
+
res.push(...formatProp(key, props[key]));
|
|
283
|
+
});
|
|
284
|
+
if (keys.length > 3) {
|
|
285
|
+
res.push(` ...`);
|
|
286
|
+
}
|
|
287
|
+
return res;
|
|
291
288
|
}
|
|
292
|
-
/* istanbul ignore next */
|
|
293
289
|
function formatProp(key, value, raw) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
value = toRaw(value);
|
|
312
|
-
return raw ? value : [`${key}=`, value];
|
|
313
|
-
}
|
|
290
|
+
if (shared.isString(value)) {
|
|
291
|
+
value = JSON.stringify(value);
|
|
292
|
+
return raw ? value : [`${key}=${value}`];
|
|
293
|
+
} else if (typeof value === "number" || typeof value === "boolean" || value == null) {
|
|
294
|
+
return raw ? value : [`${key}=${value}`];
|
|
295
|
+
} else if (isRef(value)) {
|
|
296
|
+
value = formatProp(key, toRaw(value.value), true);
|
|
297
|
+
return raw ? value : [`${key}=Ref<`, value, `>`];
|
|
298
|
+
} else if (shared.isFunction(value)) {
|
|
299
|
+
return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
|
|
300
|
+
} else {
|
|
301
|
+
value = toRaw(value);
|
|
302
|
+
return raw ? value : [`${key}=`, value];
|
|
303
|
+
}
|
|
314
304
|
}
|
|
315
305
|
|
|
316
306
|
const ErrorTypeStrings = {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core'
|
|
307
|
+
["sp"]: "serverPrefetch hook",
|
|
308
|
+
["bc"]: "beforeCreate hook",
|
|
309
|
+
["c"]: "created hook",
|
|
310
|
+
["bm"]: "beforeMount hook",
|
|
311
|
+
["m"]: "mounted hook",
|
|
312
|
+
["bu"]: "beforeUpdate hook",
|
|
313
|
+
["u"]: "updated",
|
|
314
|
+
["bum"]: "beforeUnmount hook",
|
|
315
|
+
["um"]: "unmounted hook",
|
|
316
|
+
["a"]: "activated hook",
|
|
317
|
+
["da"]: "deactivated hook",
|
|
318
|
+
["ec"]: "errorCaptured hook",
|
|
319
|
+
["rtc"]: "renderTracked hook",
|
|
320
|
+
["rtg"]: "renderTriggered hook",
|
|
321
|
+
[0]: "setup function",
|
|
322
|
+
[1]: "render function",
|
|
323
|
+
[2]: "watcher getter",
|
|
324
|
+
[3]: "watcher callback",
|
|
325
|
+
[4]: "watcher cleanup function",
|
|
326
|
+
[5]: "native event handler",
|
|
327
|
+
[6]: "component event handler",
|
|
328
|
+
[7]: "vnode hook",
|
|
329
|
+
[8]: "directive hook",
|
|
330
|
+
[9]: "transition hook",
|
|
331
|
+
[10]: "app errorHandler",
|
|
332
|
+
[11]: "app warnHandler",
|
|
333
|
+
[12]: "ref function",
|
|
334
|
+
[13]: "async component loader",
|
|
335
|
+
[14]: "scheduler flush. This is likely a Vue internals bug. Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core"
|
|
347
336
|
};
|
|
348
337
|
function callWithErrorHandling(fn, instance, type, args) {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
return res;
|
|
338
|
+
let res;
|
|
339
|
+
try {
|
|
340
|
+
res = args ? fn(...args) : fn();
|
|
341
|
+
} catch (err) {
|
|
342
|
+
handleError(err, instance, type);
|
|
343
|
+
}
|
|
344
|
+
return res;
|
|
357
345
|
}
|
|
358
346
|
function handleError(err, instance, type, throwInDev = true) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
for (let i = 0; i < errorCapturedHooks.length; i++) {
|
|
370
|
-
if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
cur = cur.parent;
|
|
376
|
-
}
|
|
377
|
-
// app-level handling
|
|
378
|
-
const appErrorHandler = instance.appContext.config.errorHandler;
|
|
379
|
-
if (appErrorHandler) {
|
|
380
|
-
callWithErrorHandling(appErrorHandler, null, 10 /* ErrorCodes.APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
|
|
347
|
+
const contextVNode = instance ? instance.vnode : null;
|
|
348
|
+
if (instance) {
|
|
349
|
+
let cur = instance.parent;
|
|
350
|
+
const exposedInstance = instance.proxy;
|
|
351
|
+
const errorInfo = ErrorTypeStrings[type] ;
|
|
352
|
+
while (cur) {
|
|
353
|
+
const errorCapturedHooks = cur.ec;
|
|
354
|
+
if (errorCapturedHooks) {
|
|
355
|
+
for (let i = 0; i < errorCapturedHooks.length; i++) {
|
|
356
|
+
if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
|
|
381
357
|
return;
|
|
358
|
+
}
|
|
382
359
|
}
|
|
360
|
+
}
|
|
361
|
+
cur = cur.parent;
|
|
362
|
+
}
|
|
363
|
+
const appErrorHandler = instance.appContext.config.errorHandler;
|
|
364
|
+
if (appErrorHandler) {
|
|
365
|
+
callWithErrorHandling(
|
|
366
|
+
appErrorHandler,
|
|
367
|
+
null,
|
|
368
|
+
10,
|
|
369
|
+
[err, exposedInstance, errorInfo]
|
|
370
|
+
);
|
|
371
|
+
return;
|
|
383
372
|
}
|
|
384
|
-
|
|
373
|
+
}
|
|
374
|
+
logError(err, type, contextVNode, throwInDev);
|
|
385
375
|
}
|
|
386
376
|
function logError(err, type, contextVNode, throwInDev = true) {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
else {
|
|
401
|
-
console.error(err);
|
|
402
|
-
}
|
|
377
|
+
{
|
|
378
|
+
const info = ErrorTypeStrings[type];
|
|
379
|
+
if (contextVNode) {
|
|
380
|
+
pushWarningContext(contextVNode);
|
|
381
|
+
}
|
|
382
|
+
warn(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
|
|
383
|
+
if (contextVNode) {
|
|
384
|
+
popWarningContext();
|
|
385
|
+
}
|
|
386
|
+
if (throwInDev) {
|
|
387
|
+
throw err;
|
|
388
|
+
} else {
|
|
389
|
+
console.error(err);
|
|
403
390
|
}
|
|
391
|
+
}
|
|
404
392
|
}
|
|
405
393
|
|
|
406
394
|
const classifyRE = /(?:^|[-_])(\w)/g;
|
|
407
|
-
const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g,
|
|
395
|
+
const classify = (str) => str.replace(classifyRE, (c) => c.toUpperCase()).replace(/[-_]/g, "");
|
|
408
396
|
function getComponentName(Component, includeInferred = true) {
|
|
409
|
-
|
|
410
|
-
? Component.displayName || Component.name
|
|
411
|
-
: Component.name || (includeInferred && Component.__name);
|
|
397
|
+
return shared.isFunction(Component) ? Component.displayName || Component.name : Component.name || includeInferred && Component.__name;
|
|
412
398
|
}
|
|
413
|
-
/* istanbul ignore next */
|
|
414
399
|
function formatComponentName(instance, Component, isRoot = false) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
if (!name && instance && instance.parent) {
|
|
423
|
-
// try to infer the name based on reverse resolution
|
|
424
|
-
const inferFromRegistry = (registry) => {
|
|
425
|
-
for (const key in registry) {
|
|
426
|
-
if (registry[key] === Component) {
|
|
427
|
-
return key;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
name =
|
|
432
|
-
inferFromRegistry(instance.components ||
|
|
433
|
-
instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
|
|
400
|
+
let name = getComponentName(Component);
|
|
401
|
+
if (!name && Component.__file) {
|
|
402
|
+
const match = Component.__file.match(/([^/\\]+)\.\w+$/);
|
|
403
|
+
if (match) {
|
|
404
|
+
name = match[1];
|
|
434
405
|
}
|
|
435
|
-
|
|
406
|
+
}
|
|
407
|
+
if (!name && instance && instance.parent) {
|
|
408
|
+
const inferFromRegistry = (registry) => {
|
|
409
|
+
for (const key in registry) {
|
|
410
|
+
if (registry[key] === Component) {
|
|
411
|
+
return key;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
name = inferFromRegistry(
|
|
416
|
+
instance.components || instance.parent.type.components
|
|
417
|
+
) || inferFromRegistry(instance.appContext.components);
|
|
418
|
+
}
|
|
419
|
+
return name ? classify(name) : isRoot ? `App` : `Anonymous`;
|
|
436
420
|
}
|
|
437
421
|
|
|
438
422
|
function ssrRenderList(source, renderItem) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
const key = keys[i];
|
|
464
|
-
renderItem(source[key], key, i);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
423
|
+
if (shared.isArray(source) || shared.isString(source)) {
|
|
424
|
+
for (let i = 0, l = source.length; i < l; i++) {
|
|
425
|
+
renderItem(source[i], i);
|
|
426
|
+
}
|
|
427
|
+
} else if (typeof source === "number") {
|
|
428
|
+
if (!Number.isInteger(source)) {
|
|
429
|
+
warn(`The v-for range expect an integer value but got ${source}.`);
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
for (let i = 0; i < source; i++) {
|
|
433
|
+
renderItem(i + 1, i);
|
|
434
|
+
}
|
|
435
|
+
} else if (shared.isObject(source)) {
|
|
436
|
+
if (source[Symbol.iterator]) {
|
|
437
|
+
const arr = Array.from(source);
|
|
438
|
+
for (let i = 0, l = arr.length; i < l; i++) {
|
|
439
|
+
renderItem(arr[i], i);
|
|
440
|
+
}
|
|
441
|
+
} else {
|
|
442
|
+
const keys = Object.keys(source);
|
|
443
|
+
for (let i = 0, l = keys.length; i < l; i++) {
|
|
444
|
+
const key = keys[i];
|
|
445
|
+
renderItem(source[key], key, i);
|
|
446
|
+
}
|
|
467
447
|
}
|
|
448
|
+
}
|
|
468
449
|
}
|
|
469
450
|
|
|
470
451
|
async function ssrRenderSuspense(push, { default: renderContent }) {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
}
|
|
452
|
+
if (renderContent) {
|
|
453
|
+
renderContent();
|
|
454
|
+
} else {
|
|
455
|
+
push(`<!---->`);
|
|
456
|
+
}
|
|
477
457
|
}
|
|
478
458
|
|
|
479
459
|
function ssrGetDirectiveProps(instance, dir, value, arg, modifiers = {}) {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
460
|
+
if (typeof dir !== "function" && dir.getSSRProps) {
|
|
461
|
+
return dir.getSSRProps(
|
|
462
|
+
{
|
|
463
|
+
dir,
|
|
464
|
+
instance,
|
|
465
|
+
value,
|
|
466
|
+
oldValue: void 0,
|
|
467
|
+
arg,
|
|
468
|
+
modifiers
|
|
469
|
+
},
|
|
470
|
+
null
|
|
471
|
+
) || {};
|
|
472
|
+
}
|
|
473
|
+
return {};
|
|
491
474
|
}
|
|
492
475
|
|
|
493
476
|
const ssrLooseEqual = shared.looseEqual;
|
|
494
477
|
function ssrLooseContain(arr, value) {
|
|
495
|
-
|
|
478
|
+
return shared.looseIndexOf(arr, value) > -1;
|
|
496
479
|
}
|
|
497
|
-
// for <input :type="type" v-model="model" value="value">
|
|
498
480
|
function ssrRenderDynamicModel(type, model, value) {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
// text types
|
|
508
|
-
return ssrRenderAttr('value', model);
|
|
509
|
-
}
|
|
481
|
+
switch (type) {
|
|
482
|
+
case "radio":
|
|
483
|
+
return shared.looseEqual(model, value) ? " checked" : "";
|
|
484
|
+
case "checkbox":
|
|
485
|
+
return (shared.isArray(model) ? ssrLooseContain(model, value) : model) ? " checked" : "";
|
|
486
|
+
default:
|
|
487
|
+
return ssrRenderAttr("value", model);
|
|
488
|
+
}
|
|
510
489
|
}
|
|
511
|
-
// for <input v-bind="obj" v-model="model">
|
|
512
490
|
function ssrGetDynamicModelProps(existingProps = {}, model) {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
// text types
|
|
523
|
-
return { value: model };
|
|
524
|
-
}
|
|
491
|
+
const { type, value } = existingProps;
|
|
492
|
+
switch (type) {
|
|
493
|
+
case "radio":
|
|
494
|
+
return shared.looseEqual(model, value) ? { checked: true } : null;
|
|
495
|
+
case "checkbox":
|
|
496
|
+
return (shared.isArray(model) ? ssrLooseContain(model, value) : model) ? { checked: true } : null;
|
|
497
|
+
default:
|
|
498
|
+
return { value: model };
|
|
499
|
+
}
|
|
525
500
|
}
|
|
526
501
|
|
|
527
|
-
// internal runtime helpers
|
|
528
|
-
|
|
529
502
|
var helpers = /*#__PURE__*/Object.freeze({
|
|
530
503
|
__proto__: null,
|
|
531
504
|
ssrGetDirectiveProps: ssrGetDirectiveProps,
|
|
@@ -549,529 +522,530 @@ var helpers = /*#__PURE__*/Object.freeze({
|
|
|
549
522
|
ssrRenderVNode: renderVNode
|
|
550
523
|
});
|
|
551
524
|
|
|
552
|
-
const compileCache = Object.create(null);
|
|
525
|
+
const compileCache = /* @__PURE__ */ Object.create(null);
|
|
553
526
|
function ssrCompile(template, instance) {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
527
|
+
const Component = instance.type;
|
|
528
|
+
const { isCustomElement, compilerOptions } = instance.appContext.config;
|
|
529
|
+
const { delimiters, compilerOptions: componentCompilerOptions } = Component;
|
|
530
|
+
const finalCompilerOptions = shared.extend(
|
|
531
|
+
shared.extend(
|
|
532
|
+
{
|
|
559
533
|
isCustomElement,
|
|
560
534
|
delimiters
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
535
|
+
},
|
|
536
|
+
compilerOptions
|
|
537
|
+
),
|
|
538
|
+
componentCompilerOptions
|
|
539
|
+
);
|
|
540
|
+
finalCompilerOptions.isCustomElement = finalCompilerOptions.isCustomElement || shared.NO;
|
|
541
|
+
finalCompilerOptions.isNativeTag = finalCompilerOptions.isNativeTag || shared.NO;
|
|
542
|
+
const cacheKey = JSON.stringify(
|
|
543
|
+
{
|
|
544
|
+
template,
|
|
545
|
+
compilerOptions: finalCompilerOptions
|
|
546
|
+
},
|
|
547
|
+
(key, value) => {
|
|
548
|
+
return shared.isFunction(value) ? value.toString() : value;
|
|
549
|
+
}
|
|
550
|
+
);
|
|
551
|
+
const cached = compileCache[cacheKey];
|
|
552
|
+
if (cached) {
|
|
553
|
+
return cached;
|
|
554
|
+
}
|
|
555
|
+
finalCompilerOptions.onError = (err) => {
|
|
556
|
+
{
|
|
557
|
+
const message = `[@vue/server-renderer] Template compilation error: ${err.message}`;
|
|
558
|
+
const codeFrame = err.loc && shared.generateCodeFrame(
|
|
566
559
|
template,
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
}
|
|
582
|
-
};
|
|
583
|
-
const { code } = compilerSsr.compile(template, finalCompilerOptions);
|
|
584
|
-
const requireMap = {
|
|
585
|
-
vue: Vue__namespace,
|
|
586
|
-
'vue/server-renderer': helpers
|
|
587
|
-
};
|
|
588
|
-
const fakeRequire = (id) => requireMap[id];
|
|
589
|
-
return (compileCache[cacheKey] = Function('require', code)(fakeRequire));
|
|
560
|
+
err.loc.start.offset,
|
|
561
|
+
err.loc.end.offset
|
|
562
|
+
);
|
|
563
|
+
Vue.warn(codeFrame ? `${message}
|
|
564
|
+
${codeFrame}` : message);
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
const { code } = compilerSsr.compile(template, finalCompilerOptions);
|
|
568
|
+
const requireMap = {
|
|
569
|
+
vue: Vue__namespace,
|
|
570
|
+
"vue/server-renderer": helpers
|
|
571
|
+
};
|
|
572
|
+
const fakeRequire = (id) => requireMap[id];
|
|
573
|
+
return compileCache[cacheKey] = Function("require", code)(fakeRequire);
|
|
590
574
|
}
|
|
591
575
|
|
|
592
|
-
const {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
576
|
+
const {
|
|
577
|
+
createComponentInstance,
|
|
578
|
+
setCurrentRenderingInstance,
|
|
579
|
+
setupComponent,
|
|
580
|
+
renderComponentRoot,
|
|
581
|
+
normalizeVNode
|
|
582
|
+
} = Vue.ssrUtils;
|
|
599
583
|
function createBuffer() {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
buffer.hasAsync = true;
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
};
|
|
584
|
+
let appendable = false;
|
|
585
|
+
const buffer = [];
|
|
586
|
+
return {
|
|
587
|
+
getBuffer() {
|
|
588
|
+
return buffer;
|
|
589
|
+
},
|
|
590
|
+
push(item) {
|
|
591
|
+
const isStringItem = shared.isString(item);
|
|
592
|
+
if (appendable && isStringItem) {
|
|
593
|
+
buffer[buffer.length - 1] += item;
|
|
594
|
+
} else {
|
|
595
|
+
buffer.push(item);
|
|
596
|
+
}
|
|
597
|
+
appendable = isStringItem;
|
|
598
|
+
if (shared.isPromise(item) || shared.isArray(item) && item.hasAsync) {
|
|
599
|
+
buffer.hasAsync = true;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
};
|
|
623
603
|
}
|
|
624
604
|
function renderComponentVNode(vnode, parentComponent = null, slotScopeId) {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
605
|
+
const instance = createComponentInstance(vnode, parentComponent, null);
|
|
606
|
+
const res = setupComponent(
|
|
607
|
+
instance,
|
|
608
|
+
true
|
|
609
|
+
/* isSSR */
|
|
610
|
+
);
|
|
611
|
+
const hasAsyncSetup = shared.isPromise(res);
|
|
612
|
+
const prefetches = instance.sp;
|
|
613
|
+
if (hasAsyncSetup || prefetches) {
|
|
614
|
+
let p = hasAsyncSetup ? res : Promise.resolve();
|
|
615
|
+
if (prefetches) {
|
|
616
|
+
p = p.then(
|
|
617
|
+
() => Promise.all(prefetches.map((prefetch) => prefetch.call(instance.proxy)))
|
|
618
|
+
).catch(() => {
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
return p.then(() => renderComponentSubTree(instance, slotScopeId));
|
|
622
|
+
} else {
|
|
623
|
+
return renderComponentSubTree(instance, slotScopeId);
|
|
624
|
+
}
|
|
644
625
|
}
|
|
645
626
|
function renderComponentSubTree(instance, slotScopeId) {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
if (
|
|
653
|
-
|
|
654
|
-
if (key.startsWith(`data-v-`)) {
|
|
655
|
-
(root.props || (root.props = {}))[key] = ``;
|
|
656
|
-
}
|
|
657
|
-
}
|
|
627
|
+
const comp = instance.type;
|
|
628
|
+
const { getBuffer, push } = createBuffer();
|
|
629
|
+
if (shared.isFunction(comp)) {
|
|
630
|
+
let root = renderComponentRoot(instance);
|
|
631
|
+
if (!comp.props) {
|
|
632
|
+
for (const key in instance.attrs) {
|
|
633
|
+
if (key.startsWith(`data-v-`)) {
|
|
634
|
+
(root.props || (root.props = {}))[key] = ``;
|
|
658
635
|
}
|
|
659
|
-
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
renderVNode(push, instance.subTree = root, instance, slotScopeId);
|
|
639
|
+
} else {
|
|
640
|
+
if ((!instance.render || instance.render === shared.NOOP) && !instance.ssrRender && !comp.ssrRender && shared.isString(comp.template)) {
|
|
641
|
+
comp.ssrRender = ssrCompile(comp.template, instance);
|
|
642
|
+
}
|
|
643
|
+
for (const e of instance.scope.effects) {
|
|
644
|
+
if (e.computed)
|
|
645
|
+
e.computed._cacheable = true;
|
|
646
|
+
}
|
|
647
|
+
const ssrRender = instance.ssrRender || comp.ssrRender;
|
|
648
|
+
if (ssrRender) {
|
|
649
|
+
let attrs = instance.inheritAttrs !== false ? instance.attrs : void 0;
|
|
650
|
+
let hasCloned = false;
|
|
651
|
+
let cur = instance;
|
|
652
|
+
while (true) {
|
|
653
|
+
const scopeId = cur.vnode.scopeId;
|
|
654
|
+
if (scopeId) {
|
|
655
|
+
if (!hasCloned) {
|
|
656
|
+
attrs = { ...attrs };
|
|
657
|
+
hasCloned = true;
|
|
658
|
+
}
|
|
659
|
+
attrs[scopeId] = "";
|
|
667
660
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
}
|
|
674
|
-
const ssrRender = instance.ssrRender || comp.ssrRender;
|
|
675
|
-
if (ssrRender) {
|
|
676
|
-
// optimized
|
|
677
|
-
// resolve fallthrough attrs
|
|
678
|
-
let attrs = instance.inheritAttrs !== false ? instance.attrs : undefined;
|
|
679
|
-
let hasCloned = false;
|
|
680
|
-
let cur = instance;
|
|
681
|
-
while (true) {
|
|
682
|
-
const scopeId = cur.vnode.scopeId;
|
|
683
|
-
if (scopeId) {
|
|
684
|
-
if (!hasCloned) {
|
|
685
|
-
attrs = { ...attrs };
|
|
686
|
-
hasCloned = true;
|
|
687
|
-
}
|
|
688
|
-
attrs[scopeId] = '';
|
|
689
|
-
}
|
|
690
|
-
const parent = cur.parent;
|
|
691
|
-
if (parent && parent.subTree && parent.subTree === cur.vnode) {
|
|
692
|
-
// parent is a non-SSR compiled component and is rendering this
|
|
693
|
-
// component as root. inherit its scopeId if present.
|
|
694
|
-
cur = parent;
|
|
695
|
-
}
|
|
696
|
-
else {
|
|
697
|
-
break;
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
if (slotScopeId) {
|
|
701
|
-
if (!hasCloned)
|
|
702
|
-
attrs = { ...attrs };
|
|
703
|
-
attrs[slotScopeId.trim()] = '';
|
|
704
|
-
}
|
|
705
|
-
// set current rendering instance for asset resolution
|
|
706
|
-
const prev = setCurrentRenderingInstance(instance);
|
|
707
|
-
try {
|
|
708
|
-
ssrRender(instance.proxy, push, instance, attrs,
|
|
709
|
-
// compiler-optimized bindings
|
|
710
|
-
instance.props, instance.setupState, instance.data, instance.ctx);
|
|
711
|
-
}
|
|
712
|
-
finally {
|
|
713
|
-
setCurrentRenderingInstance(prev);
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
else if (instance.render && instance.render !== shared.NOOP) {
|
|
717
|
-
renderVNode(push, (instance.subTree = renderComponentRoot(instance)), instance, slotScopeId);
|
|
718
|
-
}
|
|
719
|
-
else {
|
|
720
|
-
const componentName = comp.name || comp.__file || `<Anonymous>`;
|
|
721
|
-
Vue.warn(`Component ${componentName} is missing template or render function.`);
|
|
722
|
-
push(`<!---->`);
|
|
661
|
+
const parent = cur.parent;
|
|
662
|
+
if (parent && parent.subTree && parent.subTree === cur.vnode) {
|
|
663
|
+
cur = parent;
|
|
664
|
+
} else {
|
|
665
|
+
break;
|
|
723
666
|
}
|
|
667
|
+
}
|
|
668
|
+
if (slotScopeId) {
|
|
669
|
+
if (!hasCloned)
|
|
670
|
+
attrs = { ...attrs };
|
|
671
|
+
attrs[slotScopeId.trim()] = "";
|
|
672
|
+
}
|
|
673
|
+
const prev = setCurrentRenderingInstance(instance);
|
|
674
|
+
try {
|
|
675
|
+
ssrRender(
|
|
676
|
+
instance.proxy,
|
|
677
|
+
push,
|
|
678
|
+
instance,
|
|
679
|
+
attrs,
|
|
680
|
+
// compiler-optimized bindings
|
|
681
|
+
instance.props,
|
|
682
|
+
instance.setupState,
|
|
683
|
+
instance.data,
|
|
684
|
+
instance.ctx
|
|
685
|
+
);
|
|
686
|
+
} finally {
|
|
687
|
+
setCurrentRenderingInstance(prev);
|
|
688
|
+
}
|
|
689
|
+
} else if (instance.render && instance.render !== shared.NOOP) {
|
|
690
|
+
renderVNode(
|
|
691
|
+
push,
|
|
692
|
+
instance.subTree = renderComponentRoot(instance),
|
|
693
|
+
instance,
|
|
694
|
+
slotScopeId
|
|
695
|
+
);
|
|
696
|
+
} else {
|
|
697
|
+
const componentName = comp.name || comp.__file || `<Anonymous>`;
|
|
698
|
+
Vue.warn(`Component ${componentName} is missing template or render function.`);
|
|
699
|
+
push(`<!---->`);
|
|
724
700
|
}
|
|
725
|
-
|
|
701
|
+
}
|
|
702
|
+
return getBuffer();
|
|
726
703
|
}
|
|
727
704
|
function renderVNode(push, vnode, parentComponent, slotScopeId) {
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
705
|
+
const { type, shapeFlag, children } = vnode;
|
|
706
|
+
switch (type) {
|
|
707
|
+
case Vue.Text:
|
|
708
|
+
push(shared.escapeHtml(children));
|
|
709
|
+
break;
|
|
710
|
+
case Vue.Comment:
|
|
711
|
+
push(
|
|
712
|
+
children ? `<!--${shared.escapeHtmlComment(children)}-->` : `<!---->`
|
|
713
|
+
);
|
|
714
|
+
break;
|
|
715
|
+
case Vue.Static:
|
|
716
|
+
push(children);
|
|
717
|
+
break;
|
|
718
|
+
case Vue.Fragment:
|
|
719
|
+
if (vnode.slotScopeIds) {
|
|
720
|
+
slotScopeId = (slotScopeId ? slotScopeId + " " : "") + vnode.slotScopeIds.join(" ");
|
|
721
|
+
}
|
|
722
|
+
push(`<!--[-->`);
|
|
723
|
+
renderVNodeChildren(
|
|
724
|
+
push,
|
|
725
|
+
children,
|
|
726
|
+
parentComponent,
|
|
727
|
+
slotScopeId
|
|
728
|
+
);
|
|
729
|
+
push(`<!--]-->`);
|
|
730
|
+
break;
|
|
731
|
+
default:
|
|
732
|
+
if (shapeFlag & 1) {
|
|
733
|
+
renderElementVNode(push, vnode, parentComponent, slotScopeId);
|
|
734
|
+
} else if (shapeFlag & 6) {
|
|
735
|
+
push(renderComponentVNode(vnode, parentComponent, slotScopeId));
|
|
736
|
+
} else if (shapeFlag & 64) {
|
|
737
|
+
renderTeleportVNode(push, vnode, parentComponent, slotScopeId);
|
|
738
|
+
} else if (shapeFlag & 128) {
|
|
739
|
+
renderVNode(push, vnode.ssContent, parentComponent, slotScopeId);
|
|
740
|
+
} else {
|
|
741
|
+
Vue.warn(
|
|
742
|
+
"[@vue/server-renderer] Invalid VNode type:",
|
|
743
|
+
type,
|
|
744
|
+
`(${typeof type})`
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
765
748
|
}
|
|
766
749
|
function renderVNodeChildren(push, children, parentComponent, slotScopeId) {
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
750
|
+
for (let i = 0; i < children.length; i++) {
|
|
751
|
+
renderVNode(push, normalizeVNode(children[i]), parentComponent, slotScopeId);
|
|
752
|
+
}
|
|
770
753
|
}
|
|
771
754
|
function renderElementVNode(push, vnode, parentComponent, slotScopeId) {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
755
|
+
const tag = vnode.type;
|
|
756
|
+
let { props, children, shapeFlag, scopeId, dirs } = vnode;
|
|
757
|
+
let openTag = `<${tag}`;
|
|
758
|
+
if (dirs) {
|
|
759
|
+
props = applySSRDirectives(vnode, props, dirs);
|
|
760
|
+
}
|
|
761
|
+
if (props) {
|
|
762
|
+
openTag += ssrRenderAttrs(props, tag);
|
|
763
|
+
}
|
|
764
|
+
if (scopeId) {
|
|
765
|
+
openTag += ` ${scopeId}`;
|
|
766
|
+
}
|
|
767
|
+
let curParent = parentComponent;
|
|
768
|
+
let curVnode = vnode;
|
|
769
|
+
while (curParent && curVnode === curParent.subTree) {
|
|
770
|
+
curVnode = curParent.vnode;
|
|
771
|
+
if (curVnode.scopeId) {
|
|
772
|
+
openTag += ` ${curVnode.scopeId}`;
|
|
773
|
+
}
|
|
774
|
+
curParent = curParent.parent;
|
|
775
|
+
}
|
|
776
|
+
if (slotScopeId) {
|
|
777
|
+
openTag += ` ${slotScopeId}`;
|
|
778
|
+
}
|
|
779
|
+
push(openTag + `>`);
|
|
780
|
+
if (!shared.isVoidTag(tag)) {
|
|
781
|
+
let hasChildrenOverride = false;
|
|
778
782
|
if (props) {
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
else if (props.textContent) {
|
|
806
|
-
hasChildrenOverride = true;
|
|
807
|
-
push(shared.escapeHtml(props.textContent));
|
|
808
|
-
}
|
|
809
|
-
else if (tag === 'textarea' && props.value) {
|
|
810
|
-
hasChildrenOverride = true;
|
|
811
|
-
push(shared.escapeHtml(props.value));
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
if (!hasChildrenOverride) {
|
|
815
|
-
if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
|
|
816
|
-
push(shared.escapeHtml(children));
|
|
817
|
-
}
|
|
818
|
-
else if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
|
|
819
|
-
renderVNodeChildren(push, children, parentComponent, slotScopeId);
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
push(`</${tag}>`);
|
|
823
|
-
}
|
|
783
|
+
if (props.innerHTML) {
|
|
784
|
+
hasChildrenOverride = true;
|
|
785
|
+
push(props.innerHTML);
|
|
786
|
+
} else if (props.textContent) {
|
|
787
|
+
hasChildrenOverride = true;
|
|
788
|
+
push(shared.escapeHtml(props.textContent));
|
|
789
|
+
} else if (tag === "textarea" && props.value) {
|
|
790
|
+
hasChildrenOverride = true;
|
|
791
|
+
push(shared.escapeHtml(props.value));
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
if (!hasChildrenOverride) {
|
|
795
|
+
if (shapeFlag & 8) {
|
|
796
|
+
push(shared.escapeHtml(children));
|
|
797
|
+
} else if (shapeFlag & 16) {
|
|
798
|
+
renderVNodeChildren(
|
|
799
|
+
push,
|
|
800
|
+
children,
|
|
801
|
+
parentComponent,
|
|
802
|
+
slotScopeId
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
push(`</${tag}>`);
|
|
807
|
+
}
|
|
824
808
|
}
|
|
825
809
|
function applySSRDirectives(vnode, rawProps, dirs) {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
810
|
+
const toMerge = [];
|
|
811
|
+
for (let i = 0; i < dirs.length; i++) {
|
|
812
|
+
const binding = dirs[i];
|
|
813
|
+
const {
|
|
814
|
+
dir: { getSSRProps }
|
|
815
|
+
} = binding;
|
|
816
|
+
if (getSSRProps) {
|
|
817
|
+
const props = getSSRProps(binding, vnode);
|
|
818
|
+
if (props)
|
|
819
|
+
toMerge.push(props);
|
|
835
820
|
}
|
|
836
|
-
|
|
821
|
+
}
|
|
822
|
+
return Vue.mergeProps(rawProps || {}, ...toMerge);
|
|
837
823
|
}
|
|
838
824
|
function renderTeleportVNode(push, vnode, parentComponent, slotScopeId) {
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
}
|
|
845
|
-
return [];
|
|
846
|
-
}
|
|
847
|
-
if (!shared.isString(target)) {
|
|
848
|
-
Vue.warn(`[@vue/server-renderer] Teleport target must be a query selector string.`);
|
|
849
|
-
return [];
|
|
825
|
+
const target = vnode.props && vnode.props.to;
|
|
826
|
+
const disabled = vnode.props && vnode.props.disabled;
|
|
827
|
+
if (!target) {
|
|
828
|
+
if (!disabled) {
|
|
829
|
+
Vue.warn(`[@vue/server-renderer] Teleport is missing target prop.`);
|
|
850
830
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
831
|
+
return [];
|
|
832
|
+
}
|
|
833
|
+
if (!shared.isString(target)) {
|
|
834
|
+
Vue.warn(
|
|
835
|
+
`[@vue/server-renderer] Teleport target must be a query selector string.`
|
|
836
|
+
);
|
|
837
|
+
return [];
|
|
838
|
+
}
|
|
839
|
+
ssrRenderTeleport(
|
|
840
|
+
push,
|
|
841
|
+
(push2) => {
|
|
842
|
+
renderVNodeChildren(
|
|
843
|
+
push2,
|
|
844
|
+
vnode.children,
|
|
845
|
+
parentComponent,
|
|
846
|
+
slotScopeId
|
|
847
|
+
);
|
|
848
|
+
},
|
|
849
|
+
target,
|
|
850
|
+
disabled || disabled === "",
|
|
851
|
+
parentComponent
|
|
852
|
+
);
|
|
854
853
|
}
|
|
855
854
|
|
|
856
855
|
const { isVNode: isVNode$1 } = Vue.ssrUtils;
|
|
857
856
|
async function unrollBuffer$1(buffer) {
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
return ret;
|
|
873
|
-
}
|
|
874
|
-
else {
|
|
875
|
-
// sync buffer can be more efficiently unrolled without unnecessary await
|
|
876
|
-
// ticks
|
|
877
|
-
return unrollBufferSync$1(buffer);
|
|
857
|
+
if (buffer.hasAsync) {
|
|
858
|
+
let ret = "";
|
|
859
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
860
|
+
let item = buffer[i];
|
|
861
|
+
if (shared.isPromise(item)) {
|
|
862
|
+
item = await item;
|
|
863
|
+
}
|
|
864
|
+
if (shared.isString(item)) {
|
|
865
|
+
ret += item;
|
|
866
|
+
} else {
|
|
867
|
+
ret += await unrollBuffer$1(item);
|
|
868
|
+
}
|
|
878
869
|
}
|
|
870
|
+
return ret;
|
|
871
|
+
} else {
|
|
872
|
+
return unrollBufferSync$1(buffer);
|
|
873
|
+
}
|
|
879
874
|
}
|
|
880
875
|
function unrollBufferSync$1(buffer) {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
// since this is a sync buffer, child buffers are never promises
|
|
889
|
-
ret += unrollBufferSync$1(item);
|
|
890
|
-
}
|
|
876
|
+
let ret = "";
|
|
877
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
878
|
+
let item = buffer[i];
|
|
879
|
+
if (shared.isString(item)) {
|
|
880
|
+
ret += item;
|
|
881
|
+
} else {
|
|
882
|
+
ret += unrollBufferSync$1(item);
|
|
891
883
|
}
|
|
892
|
-
|
|
884
|
+
}
|
|
885
|
+
return ret;
|
|
893
886
|
}
|
|
894
887
|
async function renderToString(input, context = {}) {
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
const
|
|
906
|
-
|
|
907
|
-
if (context.__watcherHandles) {
|
|
908
|
-
for (const unwatch of context.__watcherHandles) {
|
|
909
|
-
unwatch();
|
|
910
|
-
}
|
|
888
|
+
if (isVNode$1(input)) {
|
|
889
|
+
return renderToString(Vue.createApp({ render: () => input }), context);
|
|
890
|
+
}
|
|
891
|
+
const vnode = Vue.createVNode(input._component, input._props);
|
|
892
|
+
vnode.appContext = input._context;
|
|
893
|
+
input.provide(Vue.ssrContextKey, context);
|
|
894
|
+
const buffer = await renderComponentVNode(vnode);
|
|
895
|
+
const result = await unrollBuffer$1(buffer);
|
|
896
|
+
await resolveTeleports(context);
|
|
897
|
+
if (context.__watcherHandles) {
|
|
898
|
+
for (const unwatch of context.__watcherHandles) {
|
|
899
|
+
unwatch();
|
|
911
900
|
}
|
|
912
|
-
|
|
901
|
+
}
|
|
902
|
+
return result;
|
|
913
903
|
}
|
|
914
904
|
async function resolveTeleports(context) {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
}
|
|
905
|
+
if (context.__teleportBuffers) {
|
|
906
|
+
context.teleports = context.teleports || {};
|
|
907
|
+
for (const key in context.__teleportBuffers) {
|
|
908
|
+
context.teleports[key] = await unrollBuffer$1(
|
|
909
|
+
await Promise.all([context.__teleportBuffers[key]])
|
|
910
|
+
);
|
|
922
911
|
}
|
|
912
|
+
}
|
|
923
913
|
}
|
|
924
914
|
|
|
925
915
|
const { isVNode } = Vue.ssrUtils;
|
|
926
916
|
async function unrollBuffer(buffer, stream) {
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
// sync buffer can be more efficiently unrolled without unnecessary await
|
|
943
|
-
// ticks
|
|
944
|
-
unrollBufferSync(buffer, stream);
|
|
945
|
-
}
|
|
917
|
+
if (buffer.hasAsync) {
|
|
918
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
919
|
+
let item = buffer[i];
|
|
920
|
+
if (shared.isPromise(item)) {
|
|
921
|
+
item = await item;
|
|
922
|
+
}
|
|
923
|
+
if (shared.isString(item)) {
|
|
924
|
+
stream.push(item);
|
|
925
|
+
} else {
|
|
926
|
+
await unrollBuffer(item, stream);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
} else {
|
|
930
|
+
unrollBufferSync(buffer, stream);
|
|
931
|
+
}
|
|
946
932
|
}
|
|
947
933
|
function unrollBufferSync(buffer, stream) {
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
// since this is a sync buffer, child buffers are never promises
|
|
955
|
-
unrollBufferSync(item, stream);
|
|
956
|
-
}
|
|
934
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
935
|
+
let item = buffer[i];
|
|
936
|
+
if (shared.isString(item)) {
|
|
937
|
+
stream.push(item);
|
|
938
|
+
} else {
|
|
939
|
+
unrollBufferSync(item, stream);
|
|
957
940
|
}
|
|
941
|
+
}
|
|
958
942
|
}
|
|
959
943
|
function renderToSimpleStream(input, context, stream) {
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
.catch(error => {
|
|
981
|
-
stream.destroy(error);
|
|
982
|
-
});
|
|
983
|
-
return stream;
|
|
944
|
+
if (isVNode(input)) {
|
|
945
|
+
return renderToSimpleStream(
|
|
946
|
+
Vue.createApp({ render: () => input }),
|
|
947
|
+
context,
|
|
948
|
+
stream
|
|
949
|
+
);
|
|
950
|
+
}
|
|
951
|
+
const vnode = Vue.createVNode(input._component, input._props);
|
|
952
|
+
vnode.appContext = input._context;
|
|
953
|
+
input.provide(Vue.ssrContextKey, context);
|
|
954
|
+
Promise.resolve(renderComponentVNode(vnode)).then((buffer) => unrollBuffer(buffer, stream)).then(() => resolveTeleports(context)).then(() => {
|
|
955
|
+
if (context.__watcherHandles) {
|
|
956
|
+
for (const unwatch of context.__watcherHandles) {
|
|
957
|
+
unwatch();
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
}).then(() => stream.push(null)).catch((error) => {
|
|
961
|
+
stream.destroy(error);
|
|
962
|
+
});
|
|
963
|
+
return stream;
|
|
984
964
|
}
|
|
985
|
-
/**
|
|
986
|
-
* @deprecated
|
|
987
|
-
*/
|
|
988
965
|
function renderToStream(input, context = {}) {
|
|
989
|
-
|
|
990
|
-
|
|
966
|
+
console.warn(
|
|
967
|
+
`[@vue/server-renderer] renderToStream is deprecated - use renderToNodeStream instead.`
|
|
968
|
+
);
|
|
969
|
+
return renderToNodeStream(input, context);
|
|
991
970
|
}
|
|
992
971
|
function renderToNodeStream(input, context = {}) {
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
972
|
+
const stream = new (require("stream")).Readable({ read() {
|
|
973
|
+
} }) ;
|
|
974
|
+
if (!stream) {
|
|
975
|
+
throw new Error(
|
|
976
|
+
`ESM build of renderToStream() does not support renderToNodeStream(). Use pipeToNodeWritable() with an existing Node.js Writable stream instance instead.`
|
|
977
|
+
);
|
|
978
|
+
}
|
|
979
|
+
return renderToSimpleStream(input, context, stream);
|
|
1001
980
|
}
|
|
1002
981
|
function pipeToNodeWritable(input, context = {}, writable) {
|
|
1003
|
-
|
|
982
|
+
renderToSimpleStream(input, context, {
|
|
983
|
+
push(content) {
|
|
984
|
+
if (content != null) {
|
|
985
|
+
writable.write(content);
|
|
986
|
+
} else {
|
|
987
|
+
writable.end();
|
|
988
|
+
}
|
|
989
|
+
},
|
|
990
|
+
destroy(err) {
|
|
991
|
+
writable.destroy(err);
|
|
992
|
+
}
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
function renderToWebStream(input, context = {}) {
|
|
996
|
+
if (typeof ReadableStream !== "function") {
|
|
997
|
+
throw new Error(
|
|
998
|
+
`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.`
|
|
999
|
+
);
|
|
1000
|
+
}
|
|
1001
|
+
const encoder = new TextEncoder();
|
|
1002
|
+
let cancelled = false;
|
|
1003
|
+
return new ReadableStream({
|
|
1004
|
+
start(controller) {
|
|
1005
|
+
renderToSimpleStream(input, context, {
|
|
1004
1006
|
push(content) {
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1007
|
+
if (cancelled)
|
|
1008
|
+
return;
|
|
1009
|
+
if (content != null) {
|
|
1010
|
+
controller.enqueue(encoder.encode(content));
|
|
1011
|
+
} else {
|
|
1012
|
+
controller.close();
|
|
1013
|
+
}
|
|
1011
1014
|
},
|
|
1012
1015
|
destroy(err) {
|
|
1013
|
-
|
|
1016
|
+
controller.error(err);
|
|
1014
1017
|
}
|
|
1015
|
-
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
throw new Error(`ReadableStream constructor is not available in the global scope. ` +
|
|
1020
|
-
`If the target environment does support web streams, consider using ` +
|
|
1021
|
-
`pipeToWebWritable() with an existing WritableStream instance instead.`);
|
|
1018
|
+
});
|
|
1019
|
+
},
|
|
1020
|
+
cancel() {
|
|
1021
|
+
cancelled = true;
|
|
1022
1022
|
}
|
|
1023
|
-
|
|
1024
|
-
let cancelled = false;
|
|
1025
|
-
return new ReadableStream({
|
|
1026
|
-
start(controller) {
|
|
1027
|
-
renderToSimpleStream(input, context, {
|
|
1028
|
-
push(content) {
|
|
1029
|
-
if (cancelled)
|
|
1030
|
-
return;
|
|
1031
|
-
if (content != null) {
|
|
1032
|
-
controller.enqueue(encoder.encode(content));
|
|
1033
|
-
}
|
|
1034
|
-
else {
|
|
1035
|
-
controller.close();
|
|
1036
|
-
}
|
|
1037
|
-
},
|
|
1038
|
-
destroy(err) {
|
|
1039
|
-
controller.error(err);
|
|
1040
|
-
}
|
|
1041
|
-
});
|
|
1042
|
-
},
|
|
1043
|
-
cancel() {
|
|
1044
|
-
cancelled = true;
|
|
1045
|
-
}
|
|
1046
|
-
});
|
|
1023
|
+
});
|
|
1047
1024
|
}
|
|
1048
1025
|
function pipeToWebWritable(input, context = {}, writable) {
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
writer.close();
|
|
1073
|
-
}
|
|
1074
|
-
});
|
|
1026
|
+
const writer = writable.getWriter();
|
|
1027
|
+
const encoder = new TextEncoder();
|
|
1028
|
+
let hasReady = false;
|
|
1029
|
+
try {
|
|
1030
|
+
hasReady = shared.isPromise(writer.ready);
|
|
1031
|
+
} catch (e) {
|
|
1032
|
+
}
|
|
1033
|
+
renderToSimpleStream(input, context, {
|
|
1034
|
+
async push(content) {
|
|
1035
|
+
if (hasReady) {
|
|
1036
|
+
await writer.ready;
|
|
1037
|
+
}
|
|
1038
|
+
if (content != null) {
|
|
1039
|
+
return writer.write(encoder.encode(content));
|
|
1040
|
+
} else {
|
|
1041
|
+
return writer.close();
|
|
1042
|
+
}
|
|
1043
|
+
},
|
|
1044
|
+
destroy(err) {
|
|
1045
|
+
console.log(err);
|
|
1046
|
+
writer.close();
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
1075
1049
|
}
|
|
1076
1050
|
|
|
1077
1051
|
Vue.initDirectivesForSSR();
|