Преглед изворни кода

chore: Merge branch 'main' into minor

Evan You пре 1 година
родитељ
комит
66579ea544

+ 9 - 0
CHANGELOG.md

@@ -1,3 +1,12 @@
+## [3.4.33](https://github.com/vuejs/core/compare/v3.4.32...v3.4.33) (2024-07-19)
+
+
+### Bug Fixes
+
+* **runtime-dom:** handle undefined values in v-html ([#11403](https://github.com/vuejs/core/issues/11403)) ([5df67e3](https://github.com/vuejs/core/commit/5df67e36756639ea7b923d1b139d6cb14450123b))
+
+
+
 ## [3.4.32](https://github.com/vuejs/core/compare/v3.4.31...v3.4.32) (2024-07-17)
 
 

+ 8 - 16
packages/runtime-core/src/component.ts

@@ -454,9 +454,6 @@ export interface ComponentInternalInstance {
   refs: Data
   emit: EmitFn
 
-  attrsProxy: Data | null
-  slotsProxy: Slots | null
-
   /**
    * used for keeping track of .once event handlers on components
    * @internal
@@ -659,9 +656,6 @@ export function createComponentInstance(
     setupState: EMPTY_OBJ,
     setupContext: null,
 
-    attrsProxy: null,
-    slotsProxy: null,
-
     // suspense related
     suspense,
     suspenseId: suspense ? suspense.pendingId : 0,
@@ -1104,15 +1098,12 @@ const attrsProxyHandlers = __DEV__
  * Dev-only
  */
 function getSlotsProxy(instance: ComponentInternalInstance): Slots {
-  return (
-    instance.slotsProxy ||
-    (instance.slotsProxy = new Proxy(instance.slots, {
-      get(target, key: string) {
-        track(instance, TrackOpTypes.GET, '$slots')
-        return target[key]
-      },
-    }))
-  )
+  return new Proxy(instance.slots, {
+    get(target, key: string) {
+      track(instance, TrackOpTypes.GET, '$slots')
+      return target[key]
+    },
+  })
 }
 
 export function createSetupContext(
@@ -1146,6 +1137,7 @@ export function createSetupContext(
     // We use getters in dev in case libs like test-utils overwrite instance
     // properties (overwrites should not be done in prod)
     let attrsProxy: Data
+    let slotsProxy: Slots
     return Object.freeze({
       get attrs() {
         return (
@@ -1154,7 +1146,7 @@ export function createSetupContext(
         )
       },
       get slots() {
-        return getSlotsProxy(instance)
+        return slotsProxy || (slotsProxy = getSlotsProxy(instance))
       },
       get emit() {
         return (event: string, ...args: any[]) => instance.emit(event, ...args)

+ 6 - 0
packages/runtime-dom/__tests__/patchProps.spec.ts

@@ -152,6 +152,12 @@ describe('runtime-dom: props patching', () => {
     expect(root.innerHTML).toBe(`<div><del>baz</del></div>`)
   })
 
+  test('patch innerHTML porp w/ undefined value', async () => {
+    const root = document.createElement('div')
+    render(h('div', { innerHTML: undefined }), root)
+    expect(root.innerHTML).toBe(`<div></div>`)
+  })
+
   test('textContent unmount prev children', () => {
     const fn = vi.fn()
     const comp = {

+ 1 - 1
packages/runtime-dom/src/modules/props.ts

@@ -15,7 +15,7 @@ export function patchDOMProp(
   if (key === 'innerHTML' || key === 'textContent') {
     // null value case is handled in renderer patchElement before patching
     // children
-    if (value === null) return
+    if (value == null) return
     el[key] = value
     return
   }

+ 6 - 5
scripts/utils.js

@@ -60,13 +60,14 @@ export function fuzzyMatchTarget(partialTargets, includeAllMatching) {
  */
 export async function exec(command, args, options) {
   return new Promise((resolve, reject) => {
-    const process = spawn(command, args, {
+    const _process = spawn(command, args, {
       stdio: [
         'ignore', // stdin
         'pipe', // stdout
         'pipe', // stderr
       ],
       ...options,
+      shell: process.platform === 'win32',
     })
 
     /**
@@ -78,19 +79,19 @@ export async function exec(command, args, options) {
      */
     const stdoutChunks = []
 
-    process.stderr?.on('data', chunk => {
+    _process.stderr?.on('data', chunk => {
       stderrChunks.push(chunk)
     })
 
-    process.stdout?.on('data', chunk => {
+    _process.stdout?.on('data', chunk => {
       stdoutChunks.push(chunk)
     })
 
-    process.on('error', error => {
+    _process.on('error', error => {
       reject(error)
     })
 
-    process.on('exit', code => {
+    _process.on('exit', code => {
       const ok = code === 0
       const stderr = Buffer.concat(stderrChunks).toString().trim()
       const stdout = Buffer.concat(stdoutChunks).toString().trim()