Explorar o código

feat(ssr): auto-remove initial state script if prod (#6763)

close #6761
Mark Brouch %!s(int64=8) %!d(string=hai) anos
pai
achega
2d32b5d1b6
Modificáronse 1 ficheiros con 4 adicións e 1 borrados
  1. 4 1
      src/server/template-renderer/index.js

+ 4 - 1
src/server/template-renderer/index.js

@@ -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>`
       : ''
   }