Skip to content

Commit 2d32b5d

Browse files
markbrouchyyx990803
authored andcommitted
feat(ssr): auto-remove initial state script if prod (#6763)
close #6761
1 parent dff85b2 commit 2d32b5d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/server/template-renderer/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,13 @@ export default class TemplateRenderer {
191191
contextKey = 'state',
192192
windowKey = '__INITIAL_STATE__'
193193
} = options || {}
194+
const autoRemove = process.env.NODE_ENV === 'production'
195+
? '(function(){var s;(s=document.currentScript||document.scripts[document.scripts.length-1]).parentNode.removeChild(s);}());'
196+
: ''
194197
return context[contextKey]
195198
? `<script>window.${windowKey}=${
196199
serialize(context[contextKey], { isJSON: true })
197-
}</script>`
200+
}${autoRemove}</script>`
198201
: ''
199202
}
200203

0 commit comments

Comments
 (0)