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