Skip to content

Commit

Permalink
feat(ssr): auto-remove initial state script if prod (#6763)
Browse files Browse the repository at this point in the history
close #6761
  • Loading branch information
markbrouch authored and yyx990803 committed Oct 10, 2017
1 parent dff85b2 commit 2d32b5d
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 2d32b5d

Please sign in to comment.