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