Skip to content

Commit a23744a

Browse files
committed
fix: ssr-string static include \n case html's style parse faied (fix: vuejs#11449)
1 parent ddfa1ee commit a23744a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/server/optimizing-compiler/modules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function genStyleSegments (
106106
vShowExpression: ?string
107107
): Array<StringSegment> {
108108
if (staticStyle && !styleBinding && !vShowExpression) {
109-
return [{ type: RAW, value: ` style=${JSON.stringify(staticStyle)}` }]
109+
return [{ type: RAW, value: ` style=${JSON.stringify(staticStyle.replace(/\n/g, ''))}` }];
110110
} else {
111111
return [{
112112
type: EXPRESSION,

test/ssr/ssr-string.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,24 @@ describe('SSR: renderToString', () => {
16681668
})
16691669
})
16701670

1671+
it('only static style and not v-show ', done => {
1672+
renderVmWithOptions({
1673+
template: ` <div
1674+
style="
1675+
margin-top:
1676+
0px;width: 24px;
1677+
height: 16px;
1678+
vertical-align: text-bottom;
1679+
fill: #bfbfc3;"
1680+
></div>`,
1681+
}, result => {
1682+
expect(result).toContain(
1683+
'<div data-server-rendered="true" style="width:24px;height:16px;vertical-align:text-bottom;fill:#bfbfc3;"></div>'
1684+
)
1685+
done()
1686+
})
1687+
})
1688+
16711689
function renderVmWithOptions (options, cb) {
16721690
renderToString(new Vue(options), (err, res) => {
16731691
expect(err).toBeNull()

0 commit comments

Comments
 (0)