-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
refactor: ensure HTML is stripped of generated blank lines #14274
refactor: ensure HTML is stripped of generated blank lines #14274
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Won't this break HTMLs like this? <div style="white-space: pre">
foo
bar
</div> I guess changing |
Ah, shoot, yeah. I didn't love the idea of changing |
ca17f56
to
1404bd2
Compare
const nodeStartWithLeadingWhitespace = ( | ||
node: DefaultTreeAdapterMap['node'], | ||
) => { | ||
const lineStartOffset = | ||
node.sourceCodeLocation!.startOffset - | ||
node.sourceCodeLocation!.startCol | ||
const line = s.slice( | ||
lineStartOffset, | ||
node.sourceCodeLocation!.startOffset, | ||
) | ||
return /\S/.test(line) | ||
? node.sourceCodeLocation!.startOffset | ||
: lineStartOffset | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name could probably be better, open to suggestions! My brain is failing me at the moment though.
Simply checks if the content preceding the startOffset on the line is white space only, and if so, moves the startOffset to the start of the line so we remove it too.
97c335b
to
e756d57
Compare
Co-authored-by: 翠 / green <green@sapphi.red>
b1be990
to
9754e25
Compare
lineStartOffset, | ||
node.sourceCodeLocation!.startOffset, | ||
) | ||
return /\S/.test(line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use line.trim()
instead as it's more performant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose? Personally, I'd find that to be quite unclear and the performance gain is non-existent for this specific use case. You'd need thousands of tags to make a measurable difference.
If that's what you want though I'll switch it over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also took me a while to understand what /\S/
does 😅 I'd prefer .trim()
and also put a comment above to explain what we're doing. Every little performance counts and they stack over time if we're not careful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love \S
either tbh, but that's on your linter! 😅 I believe it forced [^\s]
to that, which, fair enough, though I wasn't familiar with \S
myself.
Will update sometime tomorrow, pretty late here for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, took a bit longer to get to this. Switched over the detection and added comments hopefully clarifying which situations are being covered, lmk if you'd like to see any further revisions.
My project that works fine with
What do you think? |
@BenceSzalai Can you provide a reproduction? That seems like a reasonable suspicion, but I can't think of any failing situations. |
@rschristian: It is not trivial to make a reproduction because it is a Quasar project, so the Vite configuration is behind layers of abstraction. But what I can see looking at the exact lines in the stack trace is that this change is the cause: Namely Probably it is because my input HTML has no linebreaks at all. So that is an edge case not handled properly I guess. If I replace this line with The main thing is try to begin with a HTML where all line-breaks are removed before given to Vite. |
That shouldn't matter, we're just looking for the HTML that actually gets passed to this plugin. Inserting a log statement for the html here would probably be enough to spot the issue, if there is one. |
I did that exactly, that's how I've found out that Quasar removes all linebreaks before the HTML is given to Vite: <!DOCTYPE html><html><head><title>Web Client</title><meta charset=utf-8><meta name=description content="A new application"><meta name=format-detection content="telephone=no"><meta name=msapplication-tap-highlight content=no><meta name=viewport content="user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1,width=device-width"><link rel=icon type=image/png sizes=128x128 href=/icons/favicon-128x128.png><link rel=icon type=image/png sizes=96x96 href=/icons/favicon-96x96.png><link rel=icon type=image/png sizes=32x32 href=/icons/favicon-32x32.png><link rel=icon type=image/png sizes=16x16 href=/icons/favicon-16x16.png><link rel=icon type=image/ico href=/favicon.ico></head><body><div id=q-app></div><script type=module src=/.quasar/client-entry.js></script></body></html> And apparently the changed code cannot any more handle this. |
Perfect, thank you. Will look into it a bit later. |
Great, thanks for the quick response! |
Got it, need to Thanks for the HTML, helped track this down much quicker! |
Description
Fixes #14273
Additional context
Let me know if a test case is desired, and how I'm to add one. I did take a look around but found no obvious location; while
playground/html
exists, it appears to be entirely for browser/integration tests.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).