Skip to content

Commit

Permalink
feat(ssr): auto-remove initial state script if prod (vuejs#6763)
Browse files Browse the repository at this point in the history
  • Loading branch information
markbrouch authored and hefeng committed Jan 25, 2019
1 parent 21ccaba commit dadb1cd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/server/template-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,13 @@ export default class TemplateRenderer {
contextKey = 'state',
windowKey = '__INITIAL_STATE__'
} = options || {}
const autoRemove = process.env.NODE_ENV === 'production'
? '(function(){var s;(s=document.currentScript||document.scripts[document.scripts.length-1]).parentNode.removeChild(s);}());'
: ''
return context[contextKey]
? `<script>window.${windowKey}=${
serialize(context[contextKey], { isJSON: true })
}</script>`
}${autoRemove}</script>`
: ''
}

Expand Down

0 comments on commit dadb1cd

Please sign in to comment.