Skip to content

Commit 2312184

Browse files
authoredFeb 8, 2024··
fix(reactivity): skip non-extensible objects when using markRaw (#10289)
close #10288
1 parent 75e02b5 commit 2312184

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
 

‎packages/reactivity/__tests__/reactive.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ describe('reactivity/reactive', () => {
277277
expect(isReactive(obj.bar)).toBe(false)
278278
})
279279

280+
test('markRaw should skip non-extensible objects', () => {
281+
const obj = Object.seal({ foo: 1 })
282+
expect(() => markRaw(obj)).not.toThrowError()
283+
})
284+
280285
test('should not observe non-extensible objects', () => {
281286
const obj = reactive({
282287
foo: Object.preventExtensions({ a: 1 }),

‎packages/reactivity/src/reactive.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ export type Raw<T> = T & { [RawSymbol]?: true }
385385
* @see {@link https://vuejs.org/api/reactivity-advanced.html#markraw}
386386
*/
387387
export function markRaw<T extends object>(value: T): Raw<T> {
388-
def(value, ReactiveFlags.SKIP, true)
388+
if (Object.isExtensible(value)) {
389+
def(value, ReactiveFlags.SKIP, true)
390+
}
389391
return value
390392
}
391393

0 commit comments

Comments
 (0)
Please sign in to comment.