Просмотр исходного кода

fix(runtime-vapor): restore fallthrough prop state after errors

daiwei 1 месяц назад
Родитель
Сommit
e0c38e86db

+ 16 - 0
packages/runtime-vapor/__tests__/dom/prop.spec.ts

@@ -17,6 +17,7 @@ import {
   VaporComponentInstance,
   applyFallthroughProps,
   createComponent,
+  isApplyingFallthroughProps,
 } from '../../src/component'
 import { ref, setCurrentInstance, svgNS, xlinkNS } from '@vue/runtime-dom'
 import { makeRender } from '../_utils'
@@ -581,6 +582,21 @@ describe('patchProp', () => {
       applyFallthroughProps(el, { ['.bar']: 'next' })
       expect(fallthroughSetCount).toBe(2)
     })
+
+    test('should restore fallthrough state when dynamic props throw', () => {
+      const el = document.createElement('div')
+      const attrs: Record<string, any> = {}
+
+      Object.defineProperty(attrs, 'foo', {
+        enumerable: true,
+        get() {
+          throw new Error('fallthrough boom')
+        },
+      })
+
+      expect(() => applyFallthroughProps(el, attrs)).toThrow('fallthrough boom')
+      expect(isApplyingFallthroughProps).toBe(false)
+    })
   })
 
   describe('setText', () => {

+ 5 - 2
packages/runtime-vapor/src/component.ts

@@ -550,8 +550,11 @@ export function applyFallthroughProps(
   attrs: Record<string, any>,
 ): void {
   isApplyingFallthroughProps = true
-  setDynamicProps(el, [attrs])
-  isApplyingFallthroughProps = false
+  try {
+    setDynamicProps(el, [attrs])
+  } finally {
+    isApplyingFallthroughProps = false
+  }
 }
 
 /**