-
-
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
feat(ssr): auto-remove initial state script if prod [#6761] #6763
feat(ssr): auto-remove initial state script if prod [#6761] #6763
Conversation
Enable intial state script to automatically remove itself from the DOM if server environment is prod. vuejs#6761
I could use some help adding tests for this, not sure the best way to go about that. |
@@ -191,10 +191,13 @@ export default class TemplateRenderer { | |||
contextKey = 'state', | |||
windowKey = '__INITIAL_STATE__' | |||
} = options || {} | |||
const autoRemove = process.env.NODE_ENV === 'production' | |||
? 'var s;(s=document.currentScript||document.scripts[document.scripts.length-1]).parentNode.removeChild(s);' |
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.
document.currentScript
is not supported in IE yet, hence the fallback.
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.
This block should be wrapped in an IIFE to avoid leaking s
to global scope.
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.
Fixed in 2409ff0
@@ -191,10 +191,13 @@ export default class TemplateRenderer { | |||
contextKey = 'state', | |||
windowKey = '__INITIAL_STATE__' | |||
} = options || {} | |||
const autoRemove = process.env.NODE_ENV === 'production' | |||
? 'var s;(s=document.currentScript||document.scripts[document.scripts.length-1]).parentNode.removeChild(s);' |
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.
This block should be wrapped in an IIFE to avoid leaking s
to global scope.
Wrap auto-remove script in IIFE so that global scope is not polluted. vuejs#6761
@yyx990803 2.5.0 released 4 hours ago, and I just found the new change will cause syntax error in browser in real output will be |
Enable intial state script to automatically remove itself from the DOM if server environment is
prod. (#6761)
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
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: