refactor: ensure ssr branches are included in esm-bundler build

This commit is contained in:
Evan You
2021-09-23 15:02:19 -04:00
parent 4886a63d82
commit 87c86e4cc2
11 changed files with 52 additions and 26 deletions

View File

@@ -303,8 +303,9 @@ function callModelHook(
fn && fn(el, binding, vnode, prevVNode)
}
// SSR vnode transforms
if (__NODE_JS__) {
// SSR vnode transforms, only used when user includes client-oriented render
// function in SSR
export function initVModelForSSR() {
vModelText.getSSRProps = ({ value }) => ({ value })
vModelRadio.getSSRProps = ({ value }, vnode) => {

View File

@@ -40,14 +40,16 @@ export const vShow: ObjectDirective<VShowElement> = {
}
}
if (__NODE_JS__) {
function setDisplay(el: VShowElement, value: unknown): void {
el.style.display = value ? el._vod : 'none'
}
// SSR vnode transforms, only used when user includes client-oriented render
// function in SSR
export function initVShowForSSR() {
vShow.getSSRProps = ({ value }) => {
if (!value) {
return { style: { display: 'none' } }
}
}
}
function setDisplay(el: VShowElement, value: unknown): void {
el.style.display = value ? el._vod : 'none'
}

View File

@@ -15,7 +15,14 @@ import {
import { nodeOps } from './nodeOps'
import { patchProp } from './patchProp'
// Importing from the compiler, will be tree-shaken in prod
import { isFunction, isString, isHTMLTag, isSVGTag, extend } from '@vue/shared'
import {
isFunction,
isString,
isHTMLTag,
isSVGTag,
extend,
NOOP
} from '@vue/shared'
declare module '@vue/reactivity' {
export interface RefUnwrapBailTypes {
@@ -225,6 +232,24 @@ export {
export { withModifiers, withKeys } from './directives/vOn'
export { vShow } from './directives/vShow'
import { initVModelForSSR } from './directives/vModel'
import { initVShowForSSR } from './directives/vShow'
let ssrDirectiveInitialized = false
/**
* @internal
*/
export const initDirectivesForSSR = __SSR__
? () => {
if (!ssrDirectiveInitialized) {
ssrDirectiveInitialized = true
initVModelForSSR()
initVShowForSSR()
}
}
: NOOP
// re-export everything from core
// h, Component, reactivity API, nextTick, flags & types
export * from '@vue/runtime-core'