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