Skip to content

Commit

Permalink
fix(reactivity): skip non-extensible objects when using markRaw (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
mattersj authored Feb 8, 2024
1 parent 75e02b5 commit 2312184
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/reactivity/__tests__/reactive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ describe('reactivity/reactive', () => {
expect(isReactive(obj.bar)).toBe(false)
})

test('markRaw should skip non-extensible objects', () => {
const obj = Object.seal({ foo: 1 })
expect(() => markRaw(obj)).not.toThrowError()
})

test('should not observe non-extensible objects', () => {
const obj = reactive({
foo: Object.preventExtensions({ a: 1 }),
Expand Down
4 changes: 3 additions & 1 deletion packages/reactivity/src/reactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ export type Raw<T> = T & { [RawSymbol]?: true }
* @see {@link https://vuejs.org/api/reactivity-advanced.html#markraw}
*/
export function markRaw<T extends object>(value: T): Raw<T> {
def(value, ReactiveFlags.SKIP, true)
if (Object.isExtensible(value)) {
def(value, ReactiveFlags.SKIP, true)
}
return value
}

Expand Down

0 comments on commit 2312184

Please sign in to comment.