From 5752381a384a0928a8c8eb36b35e9181009e10b5 Mon Sep 17 00:00:00 2001 From: skirtle <65301168+skirtles-code@users.noreply.github.com> Date: Tue, 23 Apr 2024 02:50:10 +0100 Subject: [PATCH] fix(runtime-core): attrs should be readonly in functional components --- packages/runtime-core/__tests__/componentProps.spec.ts | 5 ++--- packages/runtime-core/src/componentRenderUtils.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/runtime-core/__tests__/componentProps.spec.ts b/packages/runtime-core/__tests__/componentProps.spec.ts index 04fa4206396..1cc43c91bc2 100644 --- a/packages/runtime-core/__tests__/componentProps.spec.ts +++ b/packages/runtime-core/__tests__/componentProps.spec.ts @@ -17,7 +17,6 @@ import { ref, render, serializeInner, - toRaw, toRefs, watch, } from '@vue/runtime-test' @@ -129,12 +128,12 @@ describe('component props', () => { render(h(Comp, { foo: 1 }), root) expect(props).toEqual({ foo: 1 }) expect(attrs).toEqual({ foo: 1 }) - expect(toRaw(props)).toBe(attrs) + expect(props).toBe(attrs) render(h(Comp, { bar: 2 }), root) expect(props).toEqual({ bar: 2 }) expect(attrs).toEqual({ bar: 2 }) - expect(toRaw(props)).toBe(attrs) + expect(props).toBe(attrs) }) test('boolean casting', () => { diff --git a/packages/runtime-core/src/componentRenderUtils.ts b/packages/runtime-core/src/componentRenderUtils.ts index 31a1a5fa122..3044884669a 100644 --- a/packages/runtime-core/src/componentRenderUtils.ts +++ b/packages/runtime-core/src/componentRenderUtils.ts @@ -116,7 +116,7 @@ export function renderComponentRoot( ? { get attrs() { markAttrsAccessed() - return attrs + return shallowReadonly(attrs) }, slots, emit,