提交 a5e34b3c 编写于 作者: fxy060608's avatar fxy060608

feat(ssr): globalData

上级 46efbd97
dist dist
lib \ No newline at end of file
\ No newline at end of file
...@@ -7,12 +7,8 @@ var shared = require('@vue/shared'); ...@@ -7,12 +7,8 @@ var shared = require('@vue/shared');
const sanitise = (val) => (val && JSON.parse(JSON.stringify(val))) || val; const sanitise = (val) => (val && JSON.parse(JSON.stringify(val))) || val;
const UNI_SSR = '__uniSSR'; const UNI_SSR = '__uniSSR';
const UNI_SSR_DATA = 'data'; const UNI_SSR_DATA = 'data';
const UNI_SSR_GLOBAL_DATA = 'globalData';
function getSSRDataType() {
return vue.getCurrentInstance() ? UNI_SSR_DATA : UNI_SSR_GLOBAL_DATA;
}
function assertKey(key, shallow = false) { function assertKey(key, shallow = false) {
if (!key) { if (!key) {
throw new Error(`${shallow ? 'shallowSsrRef' : 'ssrRef'}: You must provide a key.`); throw new Error(`${shallow ? 'shallowSsrRef' : 'ssrRef'}: You must provide a key.`);
...@@ -34,12 +30,18 @@ function proxy(target, track, trigger) { ...@@ -34,12 +30,18 @@ function proxy(target, track, trigger) {
}, },
}); });
} }
const globalData = {};
const ssrServerRef = (value, key, shallow = false) => { const ssrServerRef = (value, key, shallow = false) => {
const type = getSSRDataType();
assertKey(key, shallow); assertKey(key, shallow);
const ctx = vue.useSSRContext(); const ctx = vue.useSSRContext();
const __uniSSR = ctx[UNI_SSR] || (ctx[UNI_SSR] = {}); let state;
const state = __uniSSR[type] || (__uniSSR[type] = {}); if (ctx) {
const __uniSSR = ctx[UNI_SSR] || (ctx[UNI_SSR] = {});
state = __uniSSR[UNI_SSR_DATA] || (__uniSSR[UNI_SSR_DATA] = {});
}
else {
state = globalData;
}
// SSR 模式下 watchEffect 不生效 https://github.com/vuejs/vue-next/blob/master/packages/runtime-core/src/apiWatch.ts#L253 // SSR 模式下 watchEffect 不生效 https://github.com/vuejs/vue-next/blob/master/packages/runtime-core/src/apiWatch.ts#L253
// 故自定义ref // 故自定义ref
return vue.customRef((track, trigger) => { return vue.customRef((track, trigger) => {
...@@ -68,7 +70,10 @@ const shallowSsrRef = (value, key) => { ...@@ -68,7 +70,10 @@ const shallowSsrRef = (value, key) => {
{ {
return ssrServerRef(value, key, true); return ssrServerRef(value, key, true);
} }
}; };
function getSsrGlobalData() {
return sanitise(globalData);
}
// @ts-ignore // @ts-ignore
// App and Page // App and Page
...@@ -125,6 +130,7 @@ const onNavigationBarSearchInputClicked = /*#__PURE__*/ createHook(ON_NAVIGATION ...@@ -125,6 +130,7 @@ const onNavigationBarSearchInputClicked = /*#__PURE__*/ createHook(ON_NAVIGATION
const onNavigationBarSearchInputConfirmed = /*#__PURE__*/ createHook(ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED); const onNavigationBarSearchInputConfirmed = /*#__PURE__*/ createHook(ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED);
const onNavigationBarSearchInputFocusChanged = /*#__PURE__*/ createHook(ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED); const onNavigationBarSearchInputFocusChanged = /*#__PURE__*/ createHook(ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED);
exports.getSsrGlobalData = getSsrGlobalData;
exports.onAddToFavorites = onAddToFavorites; exports.onAddToFavorites = onAddToFavorites;
exports.onBackPress = onBackPress; exports.onBackPress = onBackPress;
exports.onError = onError; exports.onError = onError;
......
...@@ -2,6 +2,8 @@ import { ComponentInternalInstance } from 'vue'; ...@@ -2,6 +2,8 @@ import { ComponentInternalInstance } from 'vue';
import { ref } from 'vue'; import { ref } from 'vue';
import { shallowRef } from 'vue'; import { shallowRef } from 'vue';
export declare function getSsrGlobalData(): any;
export declare const onAddToFavorites: (hook: () => any, target?: ComponentInternalInstance | null) => any; export declare const onAddToFavorites: (hook: () => any, target?: ComponentInternalInstance | null) => any;
export declare const onBackPress: (hook: () => any, target?: ComponentInternalInstance | null) => any; export declare const onBackPress: (hook: () => any, target?: ComponentInternalInstance | null) => any;
......
import { shallowRef, ref, getCurrentInstance, isInSSRComponentSetup, injectHook } from 'vue'; import { shallowRef, ref, getCurrentInstance, isInSSRComponentSetup, injectHook } from 'vue';
import { hasOwn } from '@vue/shared';
const sanitise = (val) => (val && JSON.parse(JSON.stringify(val))) || val;
const UNI_SSR = '__uniSSR'; const UNI_SSR = '__uniSSR';
const UNI_SSR_DATA = 'data'; const UNI_SSR_DATA = 'data';
const UNI_SSR_GLOBAL_DATA = 'globalData'; const UNI_SSR_GLOBAL_DATA = 'globalData';
...@@ -20,15 +22,24 @@ const ssrClientRef = (value, key, shallow = false) => { ...@@ -20,15 +22,24 @@ const ssrClientRef = (value, key, shallow = false) => {
} }
const type = getSSRDataType(); const type = getSSRDataType();
assertKey(key, shallow); assertKey(key, shallow);
valRef.value = __uniSSR[type][key]; if (hasOwn(__uniSSR[type], key)) {
valRef.value = __uniSSR[type][key];
if (type === UNI_SSR_DATA) {
delete __uniSSR[type][key]; // TODO 非全局数据仅使用一次?否则下次还会再次使用该数据
}
}
return valRef; return valRef;
}; };
const globalData = {};
const ssrRef = (value, key) => { const ssrRef = (value, key) => {
return ssrClientRef(value, key); return ssrClientRef(value, key);
}; };
const shallowSsrRef = (value, key) => { const shallowSsrRef = (value, key) => {
return ssrClientRef(value, key, true); return ssrClientRef(value, key, true);
}; };
function getSsrGlobalData() {
return sanitise(globalData);
}
// @ts-ignore // @ts-ignore
// App and Page // App and Page
...@@ -85,4 +96,4 @@ const onNavigationBarSearchInputClicked = /*#__PURE__*/ createHook(ON_NAVIGATION ...@@ -85,4 +96,4 @@ const onNavigationBarSearchInputClicked = /*#__PURE__*/ createHook(ON_NAVIGATION
const onNavigationBarSearchInputConfirmed = /*#__PURE__*/ createHook(ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED); const onNavigationBarSearchInputConfirmed = /*#__PURE__*/ createHook(ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED);
const onNavigationBarSearchInputFocusChanged = /*#__PURE__*/ createHook(ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED); const onNavigationBarSearchInputFocusChanged = /*#__PURE__*/ createHook(ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED);
export { onAddToFavorites, onBackPress, onError, onHide, onLaunch, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onResize, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, shallowSsrRef, ssrRef }; export { getSsrGlobalData, onAddToFavorites, onBackPress, onError, onHide, onLaunch, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onResize, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, shallowSsrRef, ssrRef };
...@@ -5,7 +5,7 @@ import { ...@@ -5,7 +5,7 @@ import {
useSSRContext, useSSRContext,
getCurrentInstance, getCurrentInstance,
} from 'vue' } from 'vue'
import { isObject } from '@vue/shared' import { hasOwn, isObject } from '@vue/shared'
import { import {
sanitise, sanitise,
UNI_SSR, UNI_SSR,
...@@ -42,7 +42,12 @@ const ssrClientRef: SSRRef = (value, key, shallow = false) => { ...@@ -42,7 +42,12 @@ const ssrClientRef: SSRRef = (value, key, shallow = false) => {
} }
const type = getSSRDataType() const type = getSSRDataType()
assertKey(key, shallow) assertKey(key, shallow)
valRef.value = (__uniSSR[type] as any)[key!] if (hasOwn(__uniSSR[type], key!)) {
valRef.value = __uniSSR[type][key!]
if (type === UNI_SSR_DATA) {
delete __uniSSR[type][key!] // TODO 非全局数据仅使用一次?否则下次还会再次使用该数据
}
}
return valRef return valRef
} }
...@@ -67,12 +72,18 @@ function proxy( ...@@ -67,12 +72,18 @@ function proxy(
}) })
} }
const globalData: Record<string, any> = {}
const ssrServerRef: SSRRef = (value, key, shallow = false) => { const ssrServerRef: SSRRef = (value, key, shallow = false) => {
const type = getSSRDataType()
assertKey(key, shallow) assertKey(key, shallow)
const ctx = useSSRContext()! const ctx = useSSRContext()
const __uniSSR = ctx[UNI_SSR] || (ctx[UNI_SSR] = {}) let state: Record<string, any>
const state = __uniSSR[type] || (__uniSSR[type] = {}) if (ctx) {
const __uniSSR = ctx[UNI_SSR] || (ctx[UNI_SSR] = {})
state = __uniSSR[UNI_SSR_DATA] || (__uniSSR[UNI_SSR_DATA] = {})
} else {
state = globalData
}
// SSR 模式下 watchEffect 不生效 https://github.com/vuejs/vue-next/blob/master/packages/runtime-core/src/apiWatch.ts#L253 // SSR 模式下 watchEffect 不生效 https://github.com/vuejs/vue-next/blob/master/packages/runtime-core/src/apiWatch.ts#L253
// 故自定义ref // 故自定义ref
return customRef((track, trigger) => { return customRef((track, trigger) => {
...@@ -106,3 +117,7 @@ export const shallowSsrRef: SSRRef = (value, key) => { ...@@ -106,3 +117,7 @@ export const shallowSsrRef: SSRRef = (value, key) => {
} }
return ssrClientRef(value, key, true) return ssrClientRef(value, key, true)
} }
export function getSsrGlobalData() {
return sanitise(globalData)
}
'use strict'; 'use strict';
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
var shared = require('@vue/shared'); var shared = require('@vue/shared');
const targetMap = new WeakMap(); const targetMap = new WeakMap();
const effectStack = []; const effectStack = [];
let activeEffect; let activeEffect;
...@@ -191,8 +191,8 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) { ...@@ -191,8 +191,8 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
} }
}; };
effects.forEach(run); effects.forEach(run);
} }
const isNonTrackableKeys = /*#__PURE__*/ shared.makeMap(`__proto__,__v_isRef,__isVue`); const isNonTrackableKeys = /*#__PURE__*/ shared.makeMap(`__proto__,__v_isRef,__isVue`);
const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol) const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol)
.map(key => Symbol[key]) .map(key => Symbol[key])
...@@ -357,8 +357,8 @@ const shallowReactiveHandlers = shared.extend({}, mutableHandlers, { ...@@ -357,8 +357,8 @@ const shallowReactiveHandlers = shared.extend({}, mutableHandlers, {
// retain the reactivity of the normal readonly object. // retain the reactivity of the normal readonly object.
const shallowReadonlyHandlers = shared.extend({}, readonlyHandlers, { const shallowReadonlyHandlers = shared.extend({}, readonlyHandlers, {
get: shallowReadonlyGet get: shallowReadonlyGet
}); });
const toReactive = (value) => shared.isObject(value) ? reactive(value) : value; const toReactive = (value) => shared.isObject(value) ? reactive(value) : value;
const toReadonly = (value) => shared.isObject(value) ? readonly(value) : value; const toReadonly = (value) => shared.isObject(value) ? readonly(value) : value;
const toShallow = (value) => value; const toShallow = (value) => value;
...@@ -632,8 +632,8 @@ function checkIdentityKeys(target, has, key) { ...@@ -632,8 +632,8 @@ function checkIdentityKeys(target, has, key) {
`Avoid differentiating between the raw and reactive versions ` + `Avoid differentiating between the raw and reactive versions ` +
`of an object and only use the reactive version if possible.`); `of an object and only use the reactive version if possible.`);
} }
} }
const reactiveMap = new WeakMap(); const reactiveMap = new WeakMap();
const shallowReactiveMap = new WeakMap(); const shallowReactiveMap = new WeakMap();
const readonlyMap = new WeakMap(); const readonlyMap = new WeakMap();
...@@ -733,8 +733,8 @@ function toRaw(observed) { ...@@ -733,8 +733,8 @@ function toRaw(observed) {
function markRaw(value) { function markRaw(value) {
shared.def(value, "__v_skip" /* SKIP */, true); shared.def(value, "__v_skip" /* SKIP */, true);
return value; return value;
} }
const convert = (val) => shared.isObject(val) ? reactive(val) : val; const convert = (val) => shared.isObject(val) ? reactive(val) : val;
function isRef(r) { function isRef(r) {
return Boolean(r && r.__v_isRef === true); return Boolean(r && r.__v_isRef === true);
...@@ -838,8 +838,8 @@ function toRef(object, key) { ...@@ -838,8 +838,8 @@ function toRef(object, key) {
return isRef(object[key]) return isRef(object[key])
? object[key] ? object[key]
: new ObjectRefImpl(object, key); : new ObjectRefImpl(object, key);
} }
class ComputedRefImpl { class ComputedRefImpl {
constructor(getter, _setter, isReadonly) { constructor(getter, _setter, isReadonly) {
this._setter = _setter; this._setter = _setter;
...@@ -885,8 +885,8 @@ function computed(getterOrOptions) { ...@@ -885,8 +885,8 @@ function computed(getterOrOptions) {
setter = getterOrOptions.set; setter = getterOrOptions.set;
} }
return new ComputedRefImpl(getter, setter, shared.isFunction(getterOrOptions) || !getterOrOptions.set); return new ComputedRefImpl(getter, setter, shared.isFunction(getterOrOptions) || !getterOrOptions.set);
} }
const stack = []; const stack = [];
function pushWarningContext(vnode) { function pushWarningContext(vnode) {
stack.push(vnode); stack.push(vnode);
...@@ -999,8 +999,8 @@ function formatProp(key, value, raw) { ...@@ -999,8 +999,8 @@ function formatProp(key, value, raw) {
value = toRaw(value); value = toRaw(value);
return raw ? value : [`${key}=`, value]; return raw ? value : [`${key}=`, value];
} }
} }
const ErrorTypeStrings = { const ErrorTypeStrings = {
["bc" /* BEFORE_CREATE */]: 'beforeCreate hook', ["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
["c" /* CREATED */]: 'created hook', ["c" /* CREATED */]: 'created hook',
...@@ -1104,8 +1104,8 @@ function logError(err, type, contextVNode, throwInDev = true) { ...@@ -1104,8 +1104,8 @@ function logError(err, type, contextVNode, throwInDev = true) {
console.error(err); console.error(err);
} }
} }
} }
let isFlushing = false; let isFlushing = false;
let isFlushPending = false; let isFlushPending = false;
const queue = []; const queue = [];
...@@ -1295,8 +1295,8 @@ function checkRecursiveUpdates(seen, fn) { ...@@ -1295,8 +1295,8 @@ function checkRecursiveUpdates(seen, fn) {
seen.set(fn, count + 1); seen.set(fn, count + 1);
} }
} }
} }
/* eslint-disable no-restricted-globals */ /* eslint-disable no-restricted-globals */
let isHmrUpdating = false; let isHmrUpdating = false;
const hmrDirtyComponents = new Set(); const hmrDirtyComponents = new Set();
...@@ -1422,8 +1422,8 @@ function tryWrap(fn) { ...@@ -1422,8 +1422,8 @@ function tryWrap(fn) {
`Full reload required.`); `Full reload required.`);
} }
}; };
} }
function setDevtoolsHook(hook) { function setDevtoolsHook(hook) {
exports.devtools = hook; exports.devtools = hook;
} }
...@@ -1457,8 +1457,8 @@ function devtoolsComponentEmit(component, event, params) { ...@@ -1457,8 +1457,8 @@ function devtoolsComponentEmit(component, event, params) {
if (!exports.devtools) if (!exports.devtools)
return; return;
exports.devtools.emit("component:emit" /* COMPONENT_EMIT */, component.appContext.app, component, event, params); exports.devtools.emit("component:emit" /* COMPONENT_EMIT */, component.appContext.app, component, event, params);
} }
function emit(instance, event, ...rawArgs) { function emit(instance, event, ...rawArgs) {
const props = instance.vnode.props || shared.EMPTY_OBJ; const props = instance.vnode.props || shared.EMPTY_OBJ;
{ {
...@@ -1579,8 +1579,8 @@ function isEmitListener(options, key) { ...@@ -1579,8 +1579,8 @@ function isEmitListener(options, key) {
return (shared.hasOwn(options, key[0].toLowerCase() + key.slice(1)) || return (shared.hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
shared.hasOwn(options, shared.hyphenate(key)) || shared.hasOwn(options, shared.hyphenate(key)) ||
shared.hasOwn(options, key)); shared.hasOwn(options, key));
} }
let isRenderingCompiledSlot = 0; let isRenderingCompiledSlot = 0;
const setCompiledSlotRendering = (n) => (isRenderingCompiledSlot += n); const setCompiledSlotRendering = (n) => (isRenderingCompiledSlot += n);
/** /**
...@@ -1627,8 +1627,8 @@ function ensureValidVNode(vnodes) { ...@@ -1627,8 +1627,8 @@ function ensureValidVNode(vnodes) {
}) })
? vnodes ? vnodes
: null; : null;
} }
/** /**
* mark the current rendering instance for asset resolution (e.g. * mark the current rendering instance for asset resolution (e.g.
* resolveComponent, resolveDirective) during render * resolveComponent, resolveDirective) during render
...@@ -1698,8 +1698,8 @@ function withCtx(fn, ctx = currentRenderingInstance) { ...@@ -1698,8 +1698,8 @@ function withCtx(fn, ctx = currentRenderingInstance) {
// rendering flag. // rendering flag.
renderFnWithContext._c = true; renderFnWithContext._c = true;
return renderFnWithContext; return renderFnWithContext;
} }
/** /**
* dev only flag to track whether $attrs was used during render. * dev only flag to track whether $attrs was used during render.
* If $attrs was used during render then the warning for failed attrs * If $attrs was used during render then the warning for failed attrs
...@@ -1993,8 +1993,8 @@ function updateHOCHostEl({ vnode, parent }, el // HostNode ...@@ -1993,8 +1993,8 @@ function updateHOCHostEl({ vnode, parent }, el // HostNode
(vnode = parent.vnode).el = el; (vnode = parent.vnode).el = el;
parent = parent.parent; parent = parent.parent;
} }
} }
const isSuspense = (type) => type.__isSuspense; const isSuspense = (type) => type.__isSuspense;
// Suspense exposes a component-like API, and is treated like a component // Suspense exposes a component-like API, and is treated like a component
// in the compiler, but internally it's a special built-in type that hooks // in the compiler, but internally it's a special built-in type that hooks
...@@ -2413,8 +2413,8 @@ function setActiveBranch(suspense, branch) { ...@@ -2413,8 +2413,8 @@ function setActiveBranch(suspense, branch) {
parentComponent.vnode.el = el; parentComponent.vnode.el = el;
updateHOCHostEl(parentComponent, el); updateHOCHostEl(parentComponent, el);
} }
} }
function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
isSSR = false) { isSSR = false) {
const props = {}; const props = {};
...@@ -2812,8 +2812,8 @@ function isExplicable(type) { ...@@ -2812,8 +2812,8 @@ function isExplicable(type) {
*/ */
function isBoolean(...args) { function isBoolean(...args) {
return args.some(elem => elem.toLowerCase() === 'boolean'); return args.some(elem => elem.toLowerCase() === 'boolean');
} }
function injectHook(type, hook, target = currentInstance, prepend = false) { function injectHook(type, hook, target = currentInstance, prepend = false) {
if (target) { if (target) {
const hooks = target[type] || (target[type] = []); const hooks = target[type] || (target[type] = []);
...@@ -2868,8 +2868,8 @@ const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */); ...@@ -2868,8 +2868,8 @@ const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */); const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
const onErrorCaptured = (hook, target = currentInstance) => { const onErrorCaptured = (hook, target = currentInstance) => {
injectHook("ec" /* ERROR_CAPTURED */, hook, target); injectHook("ec" /* ERROR_CAPTURED */, hook, target);
}; };
// Simple effect. // Simple effect.
function watchEffect(effect, options) { function watchEffect(effect, options) {
return doWatch(effect, null, options); return doWatch(effect, null, options);
...@@ -3090,8 +3090,8 @@ function traverse(value, seen = new Set()) { ...@@ -3090,8 +3090,8 @@ function traverse(value, seen = new Set()) {
} }
} }
return value; return value;
} }
function useTransitionState() { function useTransitionState() {
const state = { const state = {
isMounted: false, isMounted: false,
...@@ -3402,8 +3402,8 @@ function getTransitionRawChildren(children, keepComment = false) { ...@@ -3402,8 +3402,8 @@ function getTransitionRawChildren(children, keepComment = false) {
} }
} }
return ret; return ret;
} }
const isKeepAlive = (vnode) => vnode.type.__isKeepAlive; const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
class Cache { class Cache {
constructor(max) { constructor(max) {
...@@ -3469,7 +3469,7 @@ const KeepAliveImpl = { ...@@ -3469,7 +3469,7 @@ const KeepAliveImpl = {
// if the internal renderer is not registered, it indicates that this is server-side rendering, // if the internal renderer is not registered, it indicates that this is server-side rendering,
// for KeepAlive, we just need to render its children // for KeepAlive, we just need to render its children
if (!sharedContext.renderer) { if (!sharedContext.renderer) {
return ()=>slots.default()[0]; return () => slots.default && slots.default()[0]; // fixed by xxxxxx ssr
} }
if (props.cache && shared.hasOwn(props, 'max')) { if (props.cache && shared.hasOwn(props, 'max')) {
warn('The `max` prop will be ignored if you provide a custom caching strategy'); warn('The `max` prop will be ignored if you provide a custom caching strategy');
...@@ -3747,8 +3747,8 @@ function invokeKeepAliveHooks(hooks) { ...@@ -3747,8 +3747,8 @@ function invokeKeepAliveHooks(hooks) {
} }
function resetHookState(hooks) { function resetHookState(hooks) {
hooks.forEach((hook) => (hook.__called = false)); hooks.forEach((hook) => (hook.__called = false));
} }
const isInternalKey = (key) => key[0] === '_' || key === '$stable'; const isInternalKey = (key) => key[0] === '_' || key === '$stable';
const normalizeSlotValue = (value) => shared.isArray(value) const normalizeSlotValue = (value) => shared.isArray(value)
? value.map(normalizeVNode) ? value.map(normalizeVNode)
...@@ -3851,15 +3851,15 @@ const updateSlots = (instance, children) => { ...@@ -3851,15 +3851,15 @@ const updateSlots = (instance, children) => {
} }
} }
} }
}; };
/** /**
Runtime helper for applying directives to a vnode. Example usage: Runtime helper for applying directives to a vnode. Example usage:
const comp = resolveComponent('comp') const comp = resolveComponent('comp')
const foo = resolveDirective('foo') const foo = resolveDirective('foo')
const bar = resolveDirective('bar') const bar = resolveDirective('bar')
return withDirectives(h(comp), [ return withDirectives(h(comp), [
[foo, this.x], [foo, this.x],
[bar, this.y] [bar, this.y]
...@@ -3919,8 +3919,8 @@ function invokeDirectiveHook(vnode, prevVNode, instance, name) { ...@@ -3919,8 +3919,8 @@ function invokeDirectiveHook(vnode, prevVNode, instance, name) {
]); ]);
} }
} }
} }
function createAppContext() { function createAppContext() {
return { return {
app: null, app: null,
...@@ -4083,8 +4083,8 @@ function createAppAPI(render, hydrate) { ...@@ -4083,8 +4083,8 @@ function createAppAPI(render, hydrate) {
}); });
return app; return app;
}; };
} }
let hasMismatch = false; let hasMismatch = false;
const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject'; const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
const isComment = (node) => node.nodeType === 8 /* COMMENT */; const isComment = (node) => node.nodeType === 8 /* COMMENT */;
...@@ -4391,8 +4391,8 @@ function createHydrationFunctions(rendererInternals) { ...@@ -4391,8 +4391,8 @@ function createHydrationFunctions(rendererInternals) {
return node; return node;
}; };
return [hydrate, hydrateNode]; return [hydrate, hydrateNode];
} }
let supported; let supported;
let perf; let perf;
function startMeasure(instance, type) { function startMeasure(instance, type) {
...@@ -4424,13 +4424,13 @@ function isSupported() { ...@@ -4424,13 +4424,13 @@ function isSupported() {
} }
/* eslint-enable no-restricted-globals */ /* eslint-enable no-restricted-globals */
return supported; return supported;
} }
// implementation, close to no-op // implementation, close to no-op
function defineComponent(options) { function defineComponent(options) {
return shared.isFunction(options) ? { setup: options, name: options.name } : options; return shared.isFunction(options) ? { setup: options, name: options.name } : options;
} }
const isAsyncWrapper = (i) => !!i.type.__asyncLoader; const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
function defineAsyncComponent(source) { function defineAsyncComponent(source) {
if (shared.isFunction(source)) { if (shared.isFunction(source)) {
...@@ -4558,8 +4558,8 @@ function createInnerComp(comp, { vnode: { ref, props, children } }) { ...@@ -4558,8 +4558,8 @@ function createInnerComp(comp, { vnode: { ref, props, children } }) {
// ensure inner component inherits the async wrapper's ref owner // ensure inner component inherits the async wrapper's ref owner
vnode.ref = ref; vnode.ref = ref;
return vnode; return vnode;
} }
function createDevEffectOptions(instance) { function createDevEffectOptions(instance) {
return { return {
scheduler: queueJob, scheduler: queueJob,
...@@ -5912,8 +5912,8 @@ function getSequence(arr) { ...@@ -5912,8 +5912,8 @@ function getSequence(arr) {
v = p[v]; v = p[v];
} }
return result; return result;
} }
const isTeleport = (type) => type.__isTeleport; const isTeleport = (type) => type.__isTeleport;
const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === ''); const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement; const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
...@@ -6101,8 +6101,8 @@ function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScope ...@@ -6101,8 +6101,8 @@ function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScope
return vnode.anchor && nextSibling(vnode.anchor); return vnode.anchor && nextSibling(vnode.anchor);
} }
// Force-casted public typing for h and TSX props inference // Force-casted public typing for h and TSX props inference
const Teleport = TeleportImpl; const Teleport = TeleportImpl;
const COMPONENTS = 'components'; const COMPONENTS = 'components';
const DIRECTIVES = 'directives'; const DIRECTIVES = 'directives';
/** /**
...@@ -6170,8 +6170,8 @@ function resolve(registry, name) { ...@@ -6170,8 +6170,8 @@ function resolve(registry, name) {
(registry[name] || (registry[name] ||
registry[shared.camelize(name)] || registry[shared.camelize(name)] ||
registry[shared.capitalize(shared.camelize(name))])); registry[shared.capitalize(shared.camelize(name))]));
} }
const Fragment = Symbol('Fragment' ); const Fragment = Symbol('Fragment' );
const Text = Symbol('Text' ); const Text = Symbol('Text' );
const Comment = Symbol('Comment' ); const Comment = Symbol('Comment' );
...@@ -6604,8 +6604,8 @@ function mergeProps(...args) { ...@@ -6604,8 +6604,8 @@ function mergeProps(...args) {
} }
} }
return ret; return ret;
} }
function provide(key, value) { function provide(key, value) {
if (!currentInstance) { if (!currentInstance) {
{ {
...@@ -6654,8 +6654,8 @@ function inject(key, defaultValue, treatDefaultAsFactory = false) { ...@@ -6654,8 +6654,8 @@ function inject(key, defaultValue, treatDefaultAsFactory = false) {
else { else {
warn(`inject() can only be used inside setup() or functional components.`); warn(`inject() can only be used inside setup() or functional components.`);
} }
} }
function createDuplicateChecker() { function createDuplicateChecker() {
const cache = Object.create(null); const cache = Object.create(null);
return (type, key) => { return (type, key) => {
...@@ -7056,8 +7056,8 @@ function mergeOptions(to, from, instance) { ...@@ -7056,8 +7056,8 @@ function mergeOptions(to, from, instance) {
to[key] = from[key]; to[key] = from[key];
} }
} }
} }
/** /**
* #2437 In Vue 3, functional components do not have a public instance proxy but * #2437 In Vue 3, functional components do not have a public instance proxy but
* they exist in the internal parent chain. For code that relies on traversing * they exist in the internal parent chain. For code that relies on traversing
...@@ -7316,8 +7316,8 @@ function exposeSetupStateOnRenderContext(instance) { ...@@ -7316,8 +7316,8 @@ function exposeSetupStateOnRenderContext(instance) {
set: shared.NOOP set: shared.NOOP
}); });
}); });
} }
const emptyAppContext = createAppContext(); const emptyAppContext = createAppContext();
let uid$2 = 0; let uid$2 = 0;
function createComponentInstance(vnode, parent, suspense) { function createComponentInstance(vnode, parent, suspense) {
...@@ -7664,14 +7664,14 @@ function formatComponentName(instance, Component, isRoot = false) { ...@@ -7664,14 +7664,14 @@ function formatComponentName(instance, Component, isRoot = false) {
} }
function isClassComponent(value) { function isClassComponent(value) {
return shared.isFunction(value) && '__vccOpts' in value; return shared.isFunction(value) && '__vccOpts' in value;
} }
function computed$1(getterOrOptions) { function computed$1(getterOrOptions) {
const c = computed(getterOrOptions); const c = computed(getterOrOptions);
recordInstanceBoundEffect(c.effect); recordInstanceBoundEffect(c.effect);
return c; return c;
} }
// implementation // implementation
function defineProps() { function defineProps() {
{ {
...@@ -7696,8 +7696,8 @@ function useContext() { ...@@ -7696,8 +7696,8 @@ function useContext() {
warn(`useContext() called without active instance.`); warn(`useContext() called without active instance.`);
} }
return i.setupContext || (i.setupContext = createSetupContext(i)); return i.setupContext || (i.setupContext = createSetupContext(i));
} }
// Actual implementation // Actual implementation
function h(type, propsOrChildren, children) { function h(type, propsOrChildren, children) {
const l = arguments.length; const l = arguments.length;
...@@ -7724,8 +7724,8 @@ function h(type, propsOrChildren, children) { ...@@ -7724,8 +7724,8 @@ function h(type, propsOrChildren, children) {
} }
return createVNode(type, propsOrChildren, children); return createVNode(type, propsOrChildren, children);
} }
} }
const ssrContextKey = Symbol(`ssrContext` ); const ssrContextKey = Symbol(`ssrContext` );
const useSSRContext = () => { const useSSRContext = () => {
{ {
...@@ -7736,8 +7736,8 @@ const useSSRContext = () => { ...@@ -7736,8 +7736,8 @@ const useSSRContext = () => {
} }
return ctx; return ctx;
} }
}; };
function initCustomFormatter() { function initCustomFormatter() {
/* eslint-disable no-restricted-globals */ /* eslint-disable no-restricted-globals */
if (typeof window === 'undefined') { if (typeof window === 'undefined') {
...@@ -7925,8 +7925,8 @@ function initCustomFormatter() { ...@@ -7925,8 +7925,8 @@ function initCustomFormatter() {
else { else {
window.devtoolsFormatters = [formatter]; window.devtoolsFormatters = [formatter];
} }
} }
/** /**
* Actual implementation * Actual implementation
*/ */
...@@ -7965,8 +7965,8 @@ function renderList(source, renderItem) { ...@@ -7965,8 +7965,8 @@ function renderList(source, renderItem) {
ret = []; ret = [];
} }
return ret; return ret;
} }
/** /**
* For prefixing keys in v-on="obj" with "on" * For prefixing keys in v-on="obj" with "on"
* @private * @private
...@@ -7981,8 +7981,8 @@ function toHandlers(obj) { ...@@ -7981,8 +7981,8 @@ function toHandlers(obj) {
ret[shared.toHandlerKey(key)] = obj[key]; ret[shared.toHandlerKey(key)] = obj[key];
} }
return ret; return ret;
} }
/** /**
* Compiler runtime helper for creating dynamic slots object * Compiler runtime helper for creating dynamic slots object
* @private * @private
...@@ -8002,8 +8002,8 @@ function createSlots(slots, dynamicSlots) { ...@@ -8002,8 +8002,8 @@ function createSlots(slots, dynamicSlots) {
} }
} }
return slots; return slots;
} }
// Core API ------------------------------------------------------------------ // Core API ------------------------------------------------------------------
const version = "3.0.9"; const version = "3.0.9";
const _ssrUtils = { const _ssrUtils = {
...@@ -8018,8 +8018,8 @@ const _ssrUtils = { ...@@ -8018,8 +8018,8 @@ const _ssrUtils = {
* SSR utils for \@vue/server-renderer. Only exposed in cjs builds. * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
* @internal * @internal
*/ */
const ssrUtils = (_ssrUtils ); const ssrUtils = (_ssrUtils );
const svgNS = 'http://www.w3.org/2000/svg'; const svgNS = 'http://www.w3.org/2000/svg';
const doc = (typeof document !== 'undefined' ? document : null); const doc = (typeof document !== 'undefined' ? document : null);
let tempContainer; let tempContainer;
...@@ -8093,8 +8093,8 @@ const nodeOps = { ...@@ -8093,8 +8093,8 @@ const nodeOps = {
} }
return [first, last]; return [first, last];
} }
}; };
// compiler should normalize class + :class bindings on the same element // compiler should normalize class + :class bindings on the same element
// into a single binding ['staticClass', dynamic] // into a single binding ['staticClass', dynamic]
function patchClass(el, value, isSVG) { function patchClass(el, value, isSVG) {
...@@ -8116,8 +8116,8 @@ function patchClass(el, value, isSVG) { ...@@ -8116,8 +8116,8 @@ function patchClass(el, value, isSVG) {
} }
el.className = value; el.className = value;
} }
} }
function patchStyle(el, prev, next) { function patchStyle(el, prev, next) {
const style = el.style; const style = el.style;
if (!next) { if (!next) {
...@@ -8206,8 +8206,8 @@ const normalizeRpx = (val) => { ...@@ -8206,8 +8206,8 @@ const normalizeRpx = (val) => {
}); });
} }
return val; return val;
}; };
const xlinkNS = 'http://www.w3.org/1999/xlink'; const xlinkNS = 'http://www.w3.org/1999/xlink';
function patchAttr(el, key, value, isSVG) { function patchAttr(el, key, value, isSVG) {
if (isSVG && key.startsWith('xlink:')) { if (isSVG && key.startsWith('xlink:')) {
...@@ -8229,8 +8229,8 @@ function patchAttr(el, key, value, isSVG) { ...@@ -8229,8 +8229,8 @@ function patchAttr(el, key, value, isSVG) {
el.setAttribute(key, isBoolean ? '' : value); el.setAttribute(key, isBoolean ? '' : value);
} }
} }
} }
// __UNSAFE__ // __UNSAFE__
// functions. The user is responsible for using them with only trusted content. // functions. The user is responsible for using them with only trusted content.
function patchDOMProp(el, key, value, function patchDOMProp(el, key, value,
...@@ -8285,8 +8285,8 @@ prevChildren, parentComponent, parentSuspense, unmountChildren) { ...@@ -8285,8 +8285,8 @@ prevChildren, parentComponent, parentSuspense, unmountChildren) {
`value ${value} is invalid.`, e); `value ${value} is invalid.`, e);
} }
} }
} }
// Async edge case fix requires storing an event listener's attach timestamp. // Async edge case fix requires storing an event listener's attach timestamp.
let _getNow = Date.now; let _getNow = Date.now;
// Determine what event timestamp the browser is using. Annoyingly, the // Determine what event timestamp the browser is using. Annoyingly, the
...@@ -8393,8 +8393,8 @@ function patchStopImmediatePropagation(e, value) { ...@@ -8393,8 +8393,8 @@ function patchStopImmediatePropagation(e, value) {
else { else {
return value; return value;
} }
} }
function patchWxs(el, rawName, nextValue, instance = null) { function patchWxs(el, rawName, nextValue, instance = null) {
if (!el.__wxsWatches) { if (!el.__wxsWatches) {
el.__wxsWatches = {}; el.__wxsWatches = {};
...@@ -8412,8 +8412,8 @@ function patchWxs(el, rawName, nextValue, instance = null) { ...@@ -8412,8 +8412,8 @@ function patchWxs(el, rawName, nextValue, instance = null) {
deep: true deep: true
}); });
} }
} }
const nativeOnRE = /^on[a-z]/; const nativeOnRE = /^on[a-z]/;
const forcePatchProp = (_, key) => key === 'value'; const forcePatchProp = (_, key) => key === 'value';
const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => { const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
...@@ -8495,8 +8495,8 @@ function shouldSetAsProp(el, key, value, isSVG) { ...@@ -8495,8 +8495,8 @@ function shouldSetAsProp(el, key, value, isSVG) {
return false; return false;
} }
return key in el; return key in el;
} }
function useCssModule(name = '$style') { function useCssModule(name = '$style') {
/* istanbul ignore else */ /* istanbul ignore else */
{ {
...@@ -8517,16 +8517,16 @@ function useCssModule(name = '$style') { ...@@ -8517,16 +8517,16 @@ function useCssModule(name = '$style') {
} }
return mod; return mod;
} }
} }
/** /**
* Runtime helper for SFC's CSS variable injection feature. * Runtime helper for SFC's CSS variable injection feature.
* @private * @private
*/ */
function useCssVars(getter) { function useCssVars(getter) {
return; return;
} }
const TRANSITION = 'transition'; const TRANSITION = 'transition';
const ANIMATION = 'animation'; const ANIMATION = 'animation';
// DOM Transition is a higher-order-component based on the platform-agnostic // DOM Transition is a higher-order-component based on the platform-agnostic
...@@ -8780,8 +8780,8 @@ function toMs(s) { ...@@ -8780,8 +8780,8 @@ function toMs(s) {
// synchronously force layout to put elements into a certain state // synchronously force layout to put elements into a certain state
function forceReflow() { function forceReflow() {
return document.body.offsetHeight; return document.body.offsetHeight;
} }
const positionMap = new WeakMap(); const positionMap = new WeakMap();
const newPositionMap = new WeakMap(); const newPositionMap = new WeakMap();
const TransitionGroupImpl = { const TransitionGroupImpl = {
...@@ -8901,8 +8901,8 @@ function hasCSSTransform(el, root, moveClass) { ...@@ -8901,8 +8901,8 @@ function hasCSSTransform(el, root, moveClass) {
const { hasTransform } = getTransitionInfo(clone); const { hasTransform } = getTransitionInfo(clone);
container.removeChild(clone); container.removeChild(clone);
return hasTransform; return hasTransform;
} }
const getModelAssigner = (vnode) => { const getModelAssigner = (vnode) => {
const fn = vnode.props['onUpdate:modelValue']; const fn = vnode.props['onUpdate:modelValue'];
return shared.isArray(fn) ? value => shared.invokeArrayFns(fn, value) : fn; return shared.isArray(fn) ? value => shared.invokeArrayFns(fn, value) : fn;
...@@ -9173,8 +9173,8 @@ function callModelHook(el, binding, vnode, prevVNode, hook) { ...@@ -9173,8 +9173,8 @@ function callModelHook(el, binding, vnode, prevVNode, hook) {
return { checked: true }; return { checked: true };
} }
}; };
} }
const systemModifiers = ['ctrl', 'shift', 'alt', 'meta']; const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
const modifierGuards = { const modifierGuards = {
stop: e => e.stopPropagation(), stop: e => e.stopPropagation(),
...@@ -9228,8 +9228,8 @@ const withKeys = (fn, modifiers) => { ...@@ -9228,8 +9228,8 @@ const withKeys = (fn, modifiers) => {
} }
return fn(event); return fn(event);
}; };
}; };
const vShow = { const vShow = {
beforeMount(el, { value }, { transition }) { beforeMount(el, { value }, { transition }) {
el._vod = el.style.display === 'none' ? '' : el.style.display; el._vod = el.style.display === 'none' ? '' : el.style.display;
...@@ -9277,8 +9277,8 @@ const vShow = { ...@@ -9277,8 +9277,8 @@ const vShow = {
} }
function setDisplay(el, value) { function setDisplay(el, value) {
el.style.display = value ? el._vod : 'none'; el.style.display = value ? el._vod : 'none';
} }
const rendererOptions = shared.extend({ patchProp, forcePatchProp }, nodeOps); const rendererOptions = shared.extend({ patchProp, forcePatchProp }, nodeOps);
// lazy create the renderer - this makes core renderer logic tree-shakable // lazy create the renderer - this makes core renderer logic tree-shakable
// in case the user only imports reactivity utilities from Vue. // in case the user only imports reactivity utilities from Vue.
...@@ -9379,131 +9379,237 @@ function normalizeContainer(container) { ...@@ -9379,131 +9379,237 @@ function normalizeContainer(container) {
warn(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`); warn(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
} }
return container; return container;
}
function createVueAppContext() {
return {
app: null,
config: {
performance: false,
globalProperties: {},
optionMergeStrategies: {},
errorHandler: undefined,
warnHandler: undefined
},
mixins: [],
components: {},
directives: {},
provides: Object.create(null)
};
}
let currentApp;
let currentPlugins;
function createVueSSRApp(rootComponent, rootProps = null) {
if (rootProps != null && !shared.isObject(rootProps)) {
rootProps = null;
}
currentPlugins = [];
const context = createVueAppContext();
const app = (context.app = currentApp = {
_uid: -1,
_component: rootComponent,
_props: rootProps,
_container: null,
_context: context,
version: "3.0.9",
get config() {
return context.config;
},
set config(_v) { },
use(plugin, ...options) {
currentPlugins.push([plugin, ...options]);
return app;
},
mixin(mixin) {
context.mixins.push(mixin);
return app;
},
component(name, component) {
if (!component) {
return context.components[name];
}
context.components[name] = component;
return app;
},
directive(name, directive) {
if (!directive) {
return context.directives[name];
}
context.directives[name] = directive;
return app;
},
mount() { },
unmount() { },
provide(key, value) {
context.provides[key] = value;
return app;
}
});
return app;
}
function createVueSSRAppInstance() {
const app = createSSRApp(currentApp._component, currentApp._props);
const { config, mixins, components, directives, provides } = currentApp._context;
initAppConfig(app, config);
initAppPlugins(app, currentPlugins);
initAppMixins(app, mixins);
initAppComponents(app, components);
initAppDirectives(app, directives);
initAppProvides(app, provides);
return app;
} }
function initAppConfig(app, { performance, globalProperties, optionMergeStrategies, errorHandler, warnHandler }) {
const { config } = app;
shared.extend(config, { performance, errorHandler, warnHandler });
shared.extend(config.globalProperties, globalProperties);
shared.extend(config.optionMergeStrategies, optionMergeStrategies);
return app;
}
function initAppMixins(app, mixins) {
mixins.forEach(mixin => app.mixin(mixin));
return app;
}
function initAppComponents(app, components) {
Object.keys(components).forEach(name => app.component(name, components[name]));
return app;
}
function initAppDirectives(app, directives) {
Object.keys(directives).forEach(name => app.directive(name, directives[name]));
return app;
}
function initAppProvides(app, provides) {
Object.keys(provides).forEach(name => app.provide(name, provides[name]));
return app;
}
function initAppPlugins(app, plugins) {
plugins.forEach(plugin => app.use.apply(app, plugin));
return app;
}
// This entry exports the runtime only, and is built as // This entry exports the runtime only, and is built as
const compile$1 = () => { const compile$1 = () => {
{ {
warn(`Runtime compilation is not supported in this build of Vue.` + warn(`Runtime compilation is not supported in this build of Vue.` +
(``) /* should not happen */); (``) /* should not happen */);
} }
}; };
exports.camelize = shared.camelize; exports.camelize = shared.camelize;
exports.capitalize = shared.capitalize; exports.capitalize = shared.capitalize;
exports.toDisplayString = shared.toDisplayString; exports.toDisplayString = shared.toDisplayString;
exports.toHandlerKey = shared.toHandlerKey; exports.toHandlerKey = shared.toHandlerKey;
exports.BaseTransition = BaseTransition; exports.BaseTransition = BaseTransition;
exports.Comment = Comment; exports.Comment = Comment;
exports.Fragment = Fragment; exports.Fragment = Fragment;
exports.KeepAlive = KeepAlive; exports.KeepAlive = KeepAlive;
exports.Static = Static; exports.Static = Static;
exports.Suspense = Suspense; exports.Suspense = Suspense;
exports.Teleport = Teleport; exports.Teleport = Teleport;
exports.Text = Text; exports.Text = Text;
exports.Transition = Transition; exports.Transition = Transition;
exports.TransitionGroup = TransitionGroup; exports.TransitionGroup = TransitionGroup;
exports.callWithAsyncErrorHandling = callWithAsyncErrorHandling; exports.callWithAsyncErrorHandling = callWithAsyncErrorHandling;
exports.callWithErrorHandling = callWithErrorHandling; exports.callWithErrorHandling = callWithErrorHandling;
exports.cloneVNode = cloneVNode; exports.cloneVNode = cloneVNode;
exports.compile = compile$1; exports.compile = compile$1;
exports.computed = computed$1; exports.computed = computed$1;
exports.createApp = createApp; exports.createApp = createApp;
exports.createBlock = createBlock; exports.createBlock = createBlock;
exports.createCommentVNode = createCommentVNode; exports.createCommentVNode = createCommentVNode;
exports.createHydrationRenderer = createHydrationRenderer; exports.createHydrationRenderer = createHydrationRenderer;
exports.createRenderer = createRenderer; exports.createRenderer = createRenderer;
exports.createSSRApp = createSSRApp; exports.createSSRApp = createSSRApp;
exports.createSlots = createSlots; exports.createSlots = createSlots;
exports.createStaticVNode = createStaticVNode; exports.createStaticVNode = createStaticVNode;
exports.createTextVNode = createTextVNode; exports.createTextVNode = createTextVNode;
exports.createVNode = createVNode; exports.createVNode = createVNode;
exports.createVueApp = createApp; exports.createVueApp = createApp;
exports.createVueSSRApp = createSSRApp; exports.createVueSSRApp = createVueSSRApp;
exports.customRef = customRef; exports.createVueSSRAppInstance = createVueSSRAppInstance;
exports.defineAsyncComponent = defineAsyncComponent; exports.customRef = customRef;
exports.defineComponent = defineComponent; exports.defineAsyncComponent = defineAsyncComponent;
exports.defineEmit = defineEmit; exports.defineComponent = defineComponent;
exports.defineProps = defineProps; exports.defineEmit = defineEmit;
exports.getCurrentInstance = getCurrentInstance; exports.defineProps = defineProps;
exports.getTransitionRawChildren = getTransitionRawChildren; exports.getCurrentInstance = getCurrentInstance;
exports.h = h; exports.getTransitionRawChildren = getTransitionRawChildren;
exports.handleError = handleError; exports.h = h;
exports.hydrate = hydrate; exports.handleError = handleError;
exports.initCustomFormatter = initCustomFormatter; exports.hydrate = hydrate;
exports.inject = inject; exports.initCustomFormatter = initCustomFormatter;
exports.injectHook = injectHook; exports.inject = inject;
exports.isProxy = isProxy; exports.injectHook = injectHook;
exports.isReactive = isReactive; exports.isProxy = isProxy;
exports.isReadonly = isReadonly; exports.isReactive = isReactive;
exports.isRef = isRef; exports.isReadonly = isReadonly;
exports.isRuntimeOnly = isRuntimeOnly; exports.isRef = isRef;
exports.isVNode = isVNode; exports.isRuntimeOnly = isRuntimeOnly;
exports.markRaw = markRaw; exports.isVNode = isVNode;
exports.mergeProps = mergeProps; exports.markRaw = markRaw;
exports.nextTick = nextTick; exports.mergeProps = mergeProps;
exports.onActivated = onActivated; exports.nextTick = nextTick;
exports.onBeforeActivate = onBeforeActivate; exports.onActivated = onActivated;
exports.onBeforeDeactivate = onBeforeDeactivate; exports.onBeforeActivate = onBeforeActivate;
exports.onBeforeMount = onBeforeMount; exports.onBeforeDeactivate = onBeforeDeactivate;
exports.onBeforeUnmount = onBeforeUnmount; exports.onBeforeMount = onBeforeMount;
exports.onBeforeUpdate = onBeforeUpdate; exports.onBeforeUnmount = onBeforeUnmount;
exports.onDeactivated = onDeactivated; exports.onBeforeUpdate = onBeforeUpdate;
exports.onErrorCaptured = onErrorCaptured; exports.onDeactivated = onDeactivated;
exports.onMounted = onMounted; exports.onErrorCaptured = onErrorCaptured;
exports.onRenderTracked = onRenderTracked; exports.onMounted = onMounted;
exports.onRenderTriggered = onRenderTriggered; exports.onRenderTracked = onRenderTracked;
exports.onUnmounted = onUnmounted; exports.onRenderTriggered = onRenderTriggered;
exports.onUpdated = onUpdated; exports.onUnmounted = onUnmounted;
exports.openBlock = openBlock; exports.onUpdated = onUpdated;
exports.popScopeId = popScopeId; exports.openBlock = openBlock;
exports.provide = provide; exports.popScopeId = popScopeId;
exports.proxyRefs = proxyRefs; exports.provide = provide;
exports.pushScopeId = pushScopeId; exports.proxyRefs = proxyRefs;
exports.queuePostFlushCb = queuePostFlushCb; exports.pushScopeId = pushScopeId;
exports.reactive = reactive; exports.queuePostFlushCb = queuePostFlushCb;
exports.readonly = readonly; exports.reactive = reactive;
exports.ref = ref; exports.readonly = readonly;
exports.registerRuntimeCompiler = registerRuntimeCompiler; exports.ref = ref;
exports.render = render; exports.registerRuntimeCompiler = registerRuntimeCompiler;
exports.renderList = renderList; exports.render = render;
exports.renderSlot = renderSlot; exports.renderList = renderList;
exports.resolveComponent = resolveComponent; exports.renderSlot = renderSlot;
exports.resolveDirective = resolveDirective; exports.resolveComponent = resolveComponent;
exports.resolveDynamicComponent = resolveDynamicComponent; exports.resolveDirective = resolveDirective;
exports.resolveTransitionHooks = resolveTransitionHooks; exports.resolveDynamicComponent = resolveDynamicComponent;
exports.setBlockTracking = setBlockTracking; exports.resolveTransitionHooks = resolveTransitionHooks;
exports.setDevtoolsHook = setDevtoolsHook; exports.setBlockTracking = setBlockTracking;
exports.setTransitionHooks = setTransitionHooks; exports.setDevtoolsHook = setDevtoolsHook;
exports.shallowReactive = shallowReactive; exports.setTransitionHooks = setTransitionHooks;
exports.shallowReadonly = shallowReadonly; exports.shallowReactive = shallowReactive;
exports.shallowRef = shallowRef; exports.shallowReadonly = shallowReadonly;
exports.ssrContextKey = ssrContextKey; exports.shallowRef = shallowRef;
exports.ssrUtils = ssrUtils; exports.ssrContextKey = ssrContextKey;
exports.toHandlers = toHandlers; exports.ssrUtils = ssrUtils;
exports.toRaw = toRaw; exports.toHandlers = toHandlers;
exports.toRef = toRef; exports.toRaw = toRaw;
exports.toRefs = toRefs; exports.toRef = toRef;
exports.transformVNodeArgs = transformVNodeArgs; exports.toRefs = toRefs;
exports.triggerRef = triggerRef; exports.transformVNodeArgs = transformVNodeArgs;
exports.unref = unref; exports.triggerRef = triggerRef;
exports.useContext = useContext; exports.unref = unref;
exports.useCssModule = useCssModule; exports.useContext = useContext;
exports.useCssVars = useCssVars; exports.useCssModule = useCssModule;
exports.useSSRContext = useSSRContext; exports.useCssVars = useCssVars;
exports.useTransitionState = useTransitionState; exports.useSSRContext = useSSRContext;
exports.vModelCheckbox = vModelCheckbox; exports.useTransitionState = useTransitionState;
exports.vModelDynamic = vModelDynamic; exports.vModelCheckbox = vModelCheckbox;
exports.vModelRadio = vModelRadio; exports.vModelDynamic = vModelDynamic;
exports.vModelSelect = vModelSelect; exports.vModelRadio = vModelRadio;
exports.vModelText = vModelText; exports.vModelSelect = vModelSelect;
exports.vShow = vShow; exports.vModelText = vModelText;
exports.version = version; exports.vShow = vShow;
exports.warn = warn; exports.version = version;
exports.watch = watch; exports.warn = warn;
exports.watchEffect = watchEffect; exports.watch = watch;
exports.withCtx = withCtx; exports.watchEffect = watchEffect;
exports.withDirectives = withDirectives; exports.withCtx = withCtx;
exports.withKeys = withKeys; exports.withDirectives = withDirectives;
exports.withModifiers = withModifiers; exports.withKeys = withKeys;
exports.withScopeId = withScopeId; exports.withModifiers = withModifiers;
exports.withScopeId = withScopeId;
...@@ -3457,7 +3457,7 @@ const KeepAliveImpl = { ...@@ -3457,7 +3457,7 @@ const KeepAliveImpl = {
// if the internal renderer is not registered, it indicates that this is server-side rendering, // if the internal renderer is not registered, it indicates that this is server-side rendering,
// for KeepAlive, we just need to render its children // for KeepAlive, we just need to render its children
if (!sharedContext.renderer) { if (!sharedContext.renderer) {
return slots.default; return () => slots.default && slots.default()[0]; // fixed by xxxxxx ssr
} }
if ((process.env.NODE_ENV !== 'production') && props.cache && hasOwn(props, 'max')) { if ((process.env.NODE_ENV !== 'production') && props.cache && hasOwn(props, 'max')) {
warn('The `max` prop will be ignored if you provide a custom caching strategy'); warn('The `max` prop will be ignored if you provide a custom caching strategy');
...@@ -9434,6 +9434,111 @@ function initDev() { ...@@ -9434,6 +9434,111 @@ function initDev() {
} }
} }
function createVueAppContext() {
return {
app: null,
config: {
performance: false,
globalProperties: {},
optionMergeStrategies: {},
errorHandler: undefined,
warnHandler: undefined
},
mixins: [],
components: {},
directives: {},
provides: Object.create(null)
};
}
let currentApp;
let currentPlugins;
function createVueSSRApp(rootComponent, rootProps = null) {
if (rootProps != null && !isObject(rootProps)) {
rootProps = null;
}
currentPlugins = [];
const context = createVueAppContext();
const app = (context.app = currentApp = {
_uid: -1,
_component: rootComponent,
_props: rootProps,
_container: null,
_context: context,
version: "3.0.9",
get config() {
return context.config;
},
set config(_v) { },
use(plugin, ...options) {
currentPlugins.push([plugin, ...options]);
return app;
},
mixin(mixin) {
context.mixins.push(mixin);
return app;
},
component(name, component) {
if (!component) {
return context.components[name];
}
context.components[name] = component;
return app;
},
directive(name, directive) {
if (!directive) {
return context.directives[name];
}
context.directives[name] = directive;
return app;
},
mount() { },
unmount() { },
provide(key, value) {
context.provides[key] = value;
return app;
}
});
return app;
}
function createVueSSRAppInstance() {
const app = createSSRApp(currentApp._component, currentApp._props);
const { config, mixins, components, directives, provides } = currentApp._context;
initAppConfig(app, config);
initAppPlugins(app, currentPlugins);
initAppMixins(app, mixins);
initAppComponents(app, components);
initAppDirectives(app, directives);
initAppProvides(app, provides);
return app;
}
function initAppConfig(app, { performance, globalProperties, optionMergeStrategies, errorHandler, warnHandler }) {
const { config } = app;
extend(config, { performance, errorHandler, warnHandler });
extend(config.globalProperties, globalProperties);
extend(config.optionMergeStrategies, optionMergeStrategies);
return app;
}
function initAppMixins(app, mixins) {
mixins.forEach(mixin => app.mixin(mixin));
return app;
}
function initAppComponents(app, components) {
Object.keys(components).forEach(name => app.component(name, components[name]));
return app;
}
function initAppDirectives(app, directives) {
Object.keys(directives).forEach(name => app.directive(name, directives[name]));
return app;
}
function initAppProvides(app, provides) {
Object.keys(provides).forEach(name => app.provide(name, provides[name]));
return app;
}
function initAppPlugins(app, plugins) {
plugins.forEach(plugin => app.use.apply(app, plugin));
return app;
}
// This entry exports the runtime only, and is built as // This entry exports the runtime only, and is built as
if ((process.env.NODE_ENV !== 'production')) { if ((process.env.NODE_ENV !== 'production')) {
initDev(); initDev();
...@@ -9446,4 +9551,4 @@ const compile$1 = () => { ...@@ -9446,4 +9551,4 @@ const compile$1 = () => {
} }
}; };
export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createApp as createVueApp, createSSRApp as createVueSSRApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeActivate, onBeforeDeactivate, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId }; export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createApp as createVueApp, createVueSSRApp, createVueSSRAppInstance, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeActivate, onBeforeDeactivate, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId };
import { UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA } from '@dcloudio/uni-shared' import { createVueSSRAppInstance } from 'vue'
import { renderToString } from '@vue/server-renderer' import { renderToString } from '@vue/server-renderer'
import {
UNI_SSR,
UNI_SSR_DATA,
UNI_SSR_GLOBAL_DATA,
} from '@dcloudio/uni-shared'
let AppInstance import { getSsrGlobalData } from '@dcloudio/uni-app'
function createApp(App) {
AppInstance = createVueSSRApp(App).use(plugin)
AppInstance.mount = () => {}
return AppInstance
}
export async function render(url, manifest = {}) { export async function render(url, manifest = {}) {
const app = AppInstance const app = createVueSSRAppInstance()
const router = app.router const router = app.router
// set the router to the desired URL before rendering // set the router to the desired URL before rendering
...@@ -30,12 +29,10 @@ export async function render(url, manifest = {}) { ...@@ -30,12 +29,10 @@ export async function render(url, manifest = {}) {
const preloadLinks = renderPreloadLinks(ctx.modules, manifest) const preloadLinks = renderPreloadLinks(ctx.modules, manifest)
// the SSR context // the SSR context
const __uniSSR = ctx[UNI_SSR] || (ctx[UNI_SSR] = {}) const __uniSSR = ctx[UNI_SSR] || (ctx[UNI_SSR] = {})
if(!__uniSSR[UNI_SSR_DATA]){ if (!__uniSSR[UNI_SSR_DATA]) {
__uniSSR[UNI_SSR_DATA] = {} __uniSSR[UNI_SSR_DATA] = {}
} }
if(!__uniSSR[UNI_SSR_GLOBAL_DATA]){ __uniSSR[UNI_SSR_GLOBAL_DATA] = getSsrGlobalData()
__uniSSR[UNI_SSR_GLOBAL_DATA] = {}
}
const appContext = renderAppContext(ctx) const appContext = renderAppContext(ctx)
return [html, preloadLinks, appContext] return [html, preloadLinks, appContext]
} }
...@@ -68,6 +65,6 @@ function renderPreloadLink(file) { ...@@ -68,6 +65,6 @@ function renderPreloadLink(file) {
} }
} }
function renderAppContext(ctx){ function renderAppContext(ctx) {
return `<script>window.__uniSSR = ${JSON.stringify(ctx[UNI_SSR])}</script>` return `<script>window.__uniSSR = ${JSON.stringify(ctx[UNI_SSR])}</script>`
} }
...@@ -39,14 +39,14 @@ function createApp(code: string) { ...@@ -39,14 +39,14 @@ function createApp(code: string) {
} }
function createSSRClientApp(code: string) { function createSSRClientApp(code: string) {
return `function createApp(rootComponent, rootProps) {const app = createVueSSRApp(rootComponent, rootProps).use(plugin);const oldMount = app.mount;app.mount = (selector) => app.router.isReady().then(() => oldMount.call(app, selector));return app;};${code.replace( return `function createApp(rootComponent, rootProps) {const app = createSSRApp(rootComponent, rootProps).use(plugin);const oldMount = app.mount;app.mount = (selector) => app.router.isReady().then(() => oldMount.call(app, selector));return app;};${code.replace(
'createApp', 'createApp',
'createVueSSRApp' 'createSSRApp'
)}` )}`
} }
function createSSRServerApp(code: string) { function createSSRServerApp(code: string) {
return `${generateSSRRenderCode()};${code.replace( return `function createApp(App) {return createVueSSRApp(App).use(plugin)};${generateSSRRenderCode()};${code.replace(
'createApp', 'createApp',
'createVueSSRApp' 'createVueSSRApp'
)}` )}`
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册