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

feat(ssr): globalData

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