wip(ssr): reduce reactivity overhead during ssr

This commit is contained in:
Evan You
2020-01-24 11:39:52 -05:00
parent cee36ad028
commit 25a0d4a65f
7 changed files with 50 additions and 21 deletions

View File

@@ -288,7 +288,6 @@ function setupStatefulComponent(
instance: ComponentInternalInstance,
parentSuspense: SuspenseBoundary | null
) {
let setupResult
const Component = instance.type as ComponentOptions
if (__DEV__) {
@@ -315,7 +314,9 @@ function setupStatefulComponent(
// 2. create props proxy
// the propsProxy is a reactive AND readonly proxy to the actual props.
// it will be updated in resolveProps() on updates before render
const propsProxy = (instance.propsProxy = shallowReadonly(instance.props))
const propsProxy = (instance.propsProxy = __SSR__
? instance.props
: shallowReadonly(instance.props))
// 3. call setup()
const { setup } = Component
if (setup) {
@@ -324,7 +325,7 @@ function setupStatefulComponent(
currentInstance = instance
currentSuspense = parentSuspense
setupResult = callWithErrorHandling(
const setupResult = callWithErrorHandling(
setup,
instance,
ErrorCodes.SETUP_FUNCTION,
@@ -334,7 +335,10 @@ function setupStatefulComponent(
currentSuspense = null
if (isPromise(setupResult)) {
if (__FEATURE_SUSPENSE__) {
if (__SSR__) {
// return the promise so server-renderer can wait on it
return setupResult
} else if (__FEATURE_SUSPENSE__) {
// async setup returned Promise.
// bail here and wait for re-entry.
instance.asyncDep = setupResult
@@ -350,8 +354,6 @@ function setupStatefulComponent(
} else {
finishComponentSetup(instance, parentSuspense)
}
return setupResult
}
export function handleSetupResult(
@@ -371,7 +373,7 @@ export function handleSetupResult(
}
// setup returned bindings.
// assuming a render function compiled from template is present.
instance.renderContext = reactive(setupResult)
instance.renderContext = __SSR__ ? setupResult : reactive(setupResult)
} else if (__DEV__ && setupResult !== undefined) {
warn(
`setup() should return an object. Received: ${
@@ -449,7 +451,7 @@ function finishComponentSetup(
}
if (instance.renderContext === EMPTY_OBJ) {
instance.renderContext = reactive({})
instance.renderContext = __SSR__ ? {} : reactive({})
}
}