Skip to content

Commit

Permalink
fix(compiler-dom): should bail hoisted on break content with innerHTM…
Browse files Browse the repository at this point in the history
…L (eg.tables related tags)
  • Loading branch information
underfin committed May 25, 2020
1 parent 38f2d23 commit deca18f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,18 @@ describe('stringify static html', () => {
type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
})
})

// https://github.com/vitejs/vite/issues/226
test('should bail on break content with innerHTML (eg.tables related tags)', () => {
const { ast } = compileWithStringify(
`<div><div>${repeat(
`<tr class="foo">foo</tr>`,
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT
)}</div></div>`
)
expect(ast.hoists.length).toBe(1)
expect(ast.hoists[0]).toMatchObject({
type: NodeTypes.VNODE_CALL // not CALL_EXPRESSION
})
})
})
11 changes: 10 additions & 1 deletion packages/compiler-dom/src/transforms/stringifyStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
toDisplayString,
normalizeClass,
normalizeStyle,
stringifyStyle
stringifyStyle,
makeMap
} from '@vue/shared'

export const enum StringifyThresholds {
Expand Down Expand Up @@ -59,6 +60,12 @@ type StringifiableNode = PlainElementNode | TextCallNode
* This optimization is only performed in Node.js.
*/
export const stringifyStatic: HoistTransform = (children, context) => {
if (
context.parent!.type === NodeTypes.ELEMENT &&
canNotStringifiableTag((context.parent as PlainElementNode).tag)
) {
return
}
let nc = 0 // current node count
let ec = 0 // current element with binding count
const currentChunk: StringifiableNode[] = []
Expand Down Expand Up @@ -136,6 +143,8 @@ const isStringifiableAttr = (name: string) => {
return isKnownAttr(name) || dataAriaRE.test(name)
}

const canNotStringifiableTag = makeMap('p,table,thead,tr,th,tbody,td,colspan')

const replaceHoist = (
node: StringifiableNode,
replacement: JSChildNode | null,
Expand Down

0 comments on commit deca18f

Please sign in to comment.