-
-
Notifications
You must be signed in to change notification settings - Fork 7k
fix(html): regexp match script tag ignore comment #20341
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
base: main
Are you sure you want to change the base?
Conversation
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 think stripLiteral
works with HTML files.
Maybe we can use parse5.Tokenizer
to do something similar to stripLiteral
but I'm not sure if that is performant than parsing + traversing the HTML directly.
You are right. The local test result was correct by accident. The type value in the script tag was removed, resulting in the regular expression not matching. Can we add another regular expression to match the comment content in HTML? 🤔 |
I guess we need to at least tokenize it to properly handle comments. In other words, I don't think regex is sufficient. |
Would you check the performance difference? I'd like to know how much additional overhead this would have. Also we can check the HTML with regex before parsing so that we can skip the parse if that's faster. |
I will check it. |
I created a template project containing only js for testing through I tested it locally and the results of 10 runs are as follows. It seems that when
I retested on a different device, and the updated results look reasonable. The following table shows the original logical performance of Vite through regular matching.
|
Thanks for checking the perf 💚 |
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.
Thanks!
Trying to understand this a bit better, based on the perf result, isn't the regex one better? In most apps so far I think "no importmap" setups are more common. To fix this with regex, couldn't we do |
The original regex implementation is faster than the parsing approach. But with the "regex filter early return" ( |
Ah I missed that the PR still has an early regex check, so in practice this would only slow down setups using importmaps. Still, I find 15ms a bit much for a step during html processing that only re-arranges some tags, it'll compound with other html processing we do. I would lean on keeping regex unless people are hitting problems often with it. I think thus far there weren't many issues. |
@btea I wonder if the 15ms is coming from the actual parsing or this lazy load of vite/packages/vite/src/node/plugins/html.ts Line 193 in 6bc8bf6
Also is this the total of 10 runs? or is it the average of it? |
Yes, I added |
Description
fix #20340
refs #18386