]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): skip non-extensible objects when using `markRaw` (#10289)
authorArtyom Tuchkov <throwget@gmail.com>
Thu, 8 Feb 2024 02:57:57 +0000 (06:57 +0400)
committerGitHub <noreply@github.com>
Thu, 8 Feb 2024 02:57:57 +0000 (10:57 +0800)
close #10288

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

index 5e1e0922e50481408ae77e5d73916ee865393d5b..ab953ff891abc41ae23d2f55dcba1e237e9d2886 100644 (file)
@@ -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 }),
index 6e98fedeaf401bbdf59a4d810db8adfa46e72cf6..8b94dd9a47f5c676d29128737238225ad8a43b20 100644 (file)
@@ -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
 }