@@ -23,6 +23,7 @@ import {
2323 nativeWatch ,
2424 validateProp ,
2525 isPlainObject ,
26+ isServerRendering ,
2627 isReservedAttribute
2728} from '../util/index'
2829
@@ -169,6 +170,8 @@ const computedWatcherOptions = { lazy: true }
169170function initComputed ( vm : Component , computed : Object ) {
170171 process . env . NODE_ENV !== 'production' && checkOptionType ( vm , 'computed' )
171172 const watchers = vm . _computedWatchers = Object . create ( null )
173+ // computed properties are just getters during SSR
174+ const isSSR = isServerRendering ( )
172175
173176 for ( const key in computed ) {
174177 const userDef = computed [ key ]
@@ -179,8 +182,16 @@ function initComputed (vm: Component, computed: Object) {
179182 vm
180183 )
181184 }
182- // create internal watcher for the computed property.
183- watchers [ key ] = new Watcher ( vm , getter || noop , noop , computedWatcherOptions )
185+
186+ if ( ! isSSR ) {
187+ // create internal watcher for the computed property.
188+ watchers [ key ] = new Watcher (
189+ vm ,
190+ getter || noop ,
191+ noop ,
192+ computedWatcherOptions
193+ )
194+ }
184195
185196 // component-defined computed properties are already defined on the
186197 // component prototype. We only need to define computed properties defined
@@ -197,13 +208,20 @@ function initComputed (vm: Component, computed: Object) {
197208 }
198209}
199210
200- export function defineComputed ( target : any , key : string , userDef : Object | Function ) {
211+ export function defineComputed (
212+ target : any ,
213+ key : string ,
214+ userDef : Object | Function
215+ ) {
216+ const shouldCache = ! isServerRendering ( )
201217 if ( typeof userDef === 'function' ) {
202- sharedPropertyDefinition . get = createComputedGetter ( key )
218+ sharedPropertyDefinition . get = shouldCache
219+ ? createComputedGetter ( key )
220+ : userDef
203221 sharedPropertyDefinition . set = noop
204222 } else {
205223 sharedPropertyDefinition . get = userDef . get
206- ? userDef . cache !== false
224+ ? shouldCache && userDef . cache !== false
207225 ? createComputedGetter ( key )
208226 : userDef . get
209227 : noop
0 commit comments