Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-core): preserve whitespaces in texts full of whitespaces #7829

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rudyxu1102
Copy link
Contributor

Fixes #7789

@rudyxu1102 rudyxu1102 marked this pull request as draft March 5, 2023 14:12
@rudyxu1102 rudyxu1102 marked this pull request as ready for review March 5, 2023 14:22
@rudyxu1102 rudyxu1102 marked this pull request as draft March 6, 2023 02:11
@rudyxu1102 rudyxu1102 marked this pull request as ready for review March 6, 2023 14:48
@sxzz sxzz changed the title fix(compiler): preserve whitespaces in texts full of whitespaces fix(compiler-core): preserve whitespaces in texts full of whitespaces Mar 7, 2023
Comment on lines 262 to 264
const isAllWhitespacesText =
nodes.length === 1 && /^ +$/.test(node.content) // #7789
if (!/[^\t\r\n\f ]/.test(node.content) && !isAllWhitespacesText) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping to review this, but parse.ts was removed as part of the parser rewrite.

I think this section of the new parser may be the equivalent functionality:

function condenseWhitespace(
nodes: TemplateChildNode[],
tag?: string,
): TemplateChildNode[] {
const shouldCondense = currentOptions.whitespace !== 'preserve'
let removedWhitespace = false
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i]
if (node.type === NodeTypes.TEXT) {
if (!inPre) {
if (isAllWhitespace(node.content)) {

I also confirmed that the original issue is still present in 3.4.27.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already updated, I really appreciate your time.

@rudyxu1102 rudyxu1102 force-pushed the fix/7789 branch 2 times, most recently from 527afe4 to f5beac4 Compare June 4, 2024 16:15
Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 99.1 kB 37.5 kB 33.8 kB
vue.global.prod.js 157 kB (+12 B) 57.3 kB (+3 B) 51 kB (-35 B)

Usages

Name Size Gzip Brotli
createApp 54.5 kB 21.1 kB 19.3 kB
createSSRApp 58.4 kB 22.8 kB 20.8 kB
defineCustomElement 59.1 kB 22.6 kB 20.6 kB
overall 68.1 kB 26.2 kB 23.8 kB

Copy link

pkg-pr-new bot commented Aug 21, 2024

commit: a21d48d

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@7829

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@7829

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@7829

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@7829

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@7829

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@7829

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@7829

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@7829

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@7829

vue

pnpm add https://pkg.pr.new/vue@7829

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@7829

Open in Stackblitz

@edison1105 edison1105 added scope: compiler 🐞 bug Something isn't working ready to merge The PR is ready to be merged. labels Aug 21, 2024
@edison1105 edison1105 added the 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. 🐞 bug Something isn't working ready to merge The PR is ready to be merged. scope: compiler
Projects
Status: Needs Review
Development

Successfully merging this pull request may close these issues.

Whitespace preserve does not work
3 participants