From 87c54430448005294c41803f07f517fef848f917 Mon Sep 17 00:00:00 2001 From: linzhe <40790268+linzhe141@users.noreply.github.com> Date: Tue, 28 May 2024 14:26:29 +0800 Subject: [PATCH] fix(compiler-core): should set `` tag as block to retain MathML namespace after patching (#10891) Co-authored-by: linzhe141 --- .../transforms/transformElement.spec.ts | 12 ++++++ .../src/transforms/hoistStatic.ts | 3 +- .../src/transforms/transformElement.ts | 2 +- .../runtime-dom/__tests__/nodeOps.spec.ts | 38 ++++++++++++++++++- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts index 6c2dab9625f..10b9747d1ee 100644 --- a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts +++ b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts @@ -1284,6 +1284,18 @@ describe('compiler: element transform', () => { }) }) + test(' should be forced into blocks', () => { + const ast = parse(`
`) + transform(ast, { + nodeTransforms: [transformElement], + }) + expect((ast as any).children[0].children[0].codegenNode).toMatchObject({ + type: NodeTypes.VNODE_CALL, + tag: `"math"`, + isBlock: true, + }) + }) + test('force block for runtime custom directive w/ children', () => { const { node } = parseWithElementTransform(`
hello
`) expect(node.isBlock).toBe(true) diff --git a/packages/compiler-core/src/transforms/hoistStatic.ts b/packages/compiler-core/src/transforms/hoistStatic.ts index 70a0468e519..67bdaa887bf 100644 --- a/packages/compiler-core/src/transforms/hoistStatic.ts +++ b/packages/compiler-core/src/transforms/hoistStatic.ts @@ -174,7 +174,8 @@ export function getConstantType( if ( codegenNode.isBlock && node.tag !== 'svg' && - node.tag !== 'foreignObject' + node.tag !== 'foreignObject' && + node.tag !== 'math' ) { return ConstantTypes.NOT_CONSTANT } diff --git a/packages/compiler-core/src/transforms/transformElement.ts b/packages/compiler-core/src/transforms/transformElement.ts index 5c431f9d4da..b1be06db703 100644 --- a/packages/compiler-core/src/transforms/transformElement.ts +++ b/packages/compiler-core/src/transforms/transformElement.ts @@ -117,7 +117,7 @@ export const transformElement: NodeTransform = (node, context) => { // updates inside get proper isSVG flag at runtime. (#639, #643) // This is technically web-specific, but splitting the logic out of core // leads to too much unnecessary complexity. - (tag === 'svg' || tag === 'foreignObject')) + (tag === 'svg' || tag === 'foreignObject' || tag === 'math')) // props if (props.length > 0) { diff --git a/packages/runtime-dom/__tests__/nodeOps.spec.ts b/packages/runtime-dom/__tests__/nodeOps.spec.ts index e185f14d8dd..ed30e42adee 100644 --- a/packages/runtime-dom/__tests__/nodeOps.spec.ts +++ b/packages/runtime-dom/__tests__/nodeOps.spec.ts @@ -1,5 +1,6 @@ -import { nodeOps, svgNS } from '../src/nodeOps' - +import { defineComponent, h, nextTick, ref } from 'vue' +import { mathmlNS, nodeOps, svgNS } from '../src/nodeOps' +import { render } from '@vue/runtime-dom' describe('runtime-dom: node-ops', () => { test("the