From ef292a8d904c092442505b38d712fa3a70e6e4c2 Mon Sep 17 00:00:00 2001 From: Ilya Golovin Date: Tue, 2 Jul 2024 15:17:22 +0300 Subject: [PATCH] fix: do not warn Symbol.unscopables access --- .../__tests__/componentPublicInstance.spec.ts | 4 ++-- packages/runtime-core/src/componentPublicInstance.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/runtime-core/__tests__/componentPublicInstance.spec.ts b/packages/runtime-core/__tests__/componentPublicInstance.spec.ts index 37c228a5104..fb194c8b457 100644 --- a/packages/runtime-core/__tests__/componentPublicInstance.spec.ts +++ b/packages/runtime-core/__tests__/componentPublicInstance.spec.ts @@ -443,7 +443,7 @@ describe('component: proxy', () => { ).not.toHaveBeenWarned() }) - test('should allow symbol to access on render', () => { + test('should not warn Symbol.unscopables access on render', () => { const Comp = { render() { if ((this as any)[Symbol.unscopables]) { @@ -460,7 +460,7 @@ describe('component: proxy', () => { `Property ${JSON.stringify( Symbol.unscopables, )} was accessed during render ` + `but is not defined on instance.`, - ).toHaveBeenWarned() + ).not.toHaveBeenWarned() }) test('should prevent mutating script setup bindings', () => { diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index fd227774d5e..e2aa5d561d6 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -308,7 +308,14 @@ const hasSetupBinding = (state: Data, key: string) => state !== EMPTY_OBJ && !state.__isScriptSetup && hasOwn(state, key) export const PublicInstanceProxyHandlers: ProxyHandler = { - get({ _: instance }: ComponentRenderContext, key: string) { + get( + { _: instance }: ComponentRenderContext, + key: string | typeof Symbol.unscopables, + ) { + if (key === Symbol.unscopables) { + return + } + if (key === ReactiveFlags.SKIP) { return true }