-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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(vdom): avoid executing root level script tags #11487
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.
Thanks for the PR! I think this should be done at the compilation level (like the other removal of script
). Right now Vue.compile('<script />')
still creates a render function that renders the script, but it should just be a render function that returns null
Aha! I've thought about fix this bug at the compilation level! If so, I will work on it. |
if the render function returns null, Vue will output a comment node. But still, it is better that way, yes |
Hi, now I fix this bug at the compilation level. The output of the render function is as follows:
: ) |
src/compiler/codegen/index.js
Outdated
@@ -45,7 +45,7 @@ export function generate ( | |||
options: CompilerOptions | |||
): CodegenResult { | |||
const state = new CodegenState(options) | |||
const code = ast ? genElement(ast, state) : '_c("div")' | |||
const code = ast ? (ast.tag === 'script' ? 'null' : genElement(ast, state) ) : '_c("div")' |
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.
can you add a comment above referencing the original issue?
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.
ok, I will add the issue
I had added a comment referencing the original issue in the PR. : ) |
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!
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.
These are great changes!
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
Root level <script> tags should not be executed, for consistent behavior. So I remove the code in <script> tag when the <script> tag is the root element of the template.
fix #11483