await nextTick()
expect(App.updated).toHaveBeenCalledTimes(0)
})
+
+ describe('render with access caches', () => {
+ // #3297
+ test('should not set the access cache in the data() function (production mode)', () => {
+ const Comp = {
+ data() {
+ ;(this as any).foo
+ return { foo: 1 }
+ },
+ render() {
+ return h('h1', (this as any).foo)
+ }
+ }
+ const root = nodeOps.createElement('div')
+
+ __DEV__ = false
+ render(h(Comp), root)
+ __DEV__ = true
+ expect(serializeInner(root)).toBe(`<h1>1</h1>`)
+ })
+ })
})
type DataFn = (vm: ComponentPublicInstance) => any
-export let isInBeforeCreate = false
+export let shouldCacheAccess = true
export function applyOptions(
instance: ComponentInternalInstance,
// applyOptions is called non-as-mixin once per instance
if (!asMixin) {
- isInBeforeCreate = true
+ shouldCacheAccess = false
callSyncHook(
'beforeCreate',
LifecycleHooks.BEFORE_CREATE,
instance,
globalMixins
)
- isInBeforeCreate = false
+ shouldCacheAccess = true
// global mixins are applied first
applyMixins(
instance,
`Plain object usage is no longer supported.`
)
}
+ shouldCacheAccess = false
const data = dataFn.call(publicThis, publicThis)
+ shouldCacheAccess = true
if (__DEV__ && isPromise(data)) {
warn(
`data() returned a Promise - note data() cannot be async; If you ` +
OptionTypesType,
OptionTypesKeys,
resolveMergedOptions,
- isInBeforeCreate
+ shouldCacheAccess
} from './componentOptions'
import { EmitsOptions, EmitFn } from './componentEmits'
import { Slots } from './componentSlots'
} else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
accessCache![key] = AccessTypes.CONTEXT
return ctx[key]
- } else if (!__FEATURE_OPTIONS_API__ || !isInBeforeCreate) {
+ } else if (!__FEATURE_OPTIONS_API__ || shouldCacheAccess) {
accessCache![key] = AccessTypes.OTHER
}
}