@@ -22,7 +22,7 @@ function createContext (context) {
22
22
return sandbox
23
23
}
24
24
25
- function compileModule ( files , basedir ) {
25
+ function compileModule ( files , basedir , runInNewContext ) {
26
26
const compiledScripts = { }
27
27
const resolvedModules = { }
28
28
@@ -46,7 +46,9 @@ function compileModule (files, basedir) {
46
46
}
47
47
48
48
const script = getCompiledScript ( filename )
49
- const compiledWrapper = script . runInNewContext ( context )
49
+ const compiledWrapper = runInNewContext
50
+ ? script . runInNewContext ( context )
51
+ : script . runInThisContext ( )
50
52
const m = { exports : { } }
51
53
const r = file => {
52
54
file = path . join ( '.' , file )
@@ -87,7 +89,7 @@ function deepClone (val) {
87
89
}
88
90
89
91
export function createBundleRunner ( entry , files , basedir , runInNewContext ) {
90
- const evaluate = compileModule ( files , basedir )
92
+ const evaluate = compileModule ( files , basedir , runInNewContext )
91
93
if ( runInNewContext ) {
92
94
// new context mode: creates a fresh context and re-evaluate the bundle
93
95
// on each render. Ensures entire application state is fresh for each
@@ -102,19 +104,17 @@ export function createBundleRunner (entry, files, basedir, runInNewContext) {
102
104
// each render, it simply calls the exported function. This avoids the
103
105
// module evaluation costs but requires the source code to be structured
104
106
// slightly differently.
105
-
106
- // the initial context is only used for collecting possible non-component
107
- // styles injected by vue-style-loader.
108
- const initialContext = { }
109
- const sharedContext = createContext ( initialContext )
110
-
111
107
let runner // lazy creation so that errors can be caught by user
108
+ let initialContext
112
109
return ( userContext = { } ) => new Promise ( resolve => {
113
110
if ( ! runner ) {
114
- runner = evaluate ( entry , sharedContext )
111
+ // the initial context is only used for collecting possible non-component
112
+ // styles injected by vue-style-loader.
113
+ initialContext = global . __VUE_SSR_CONTEXT__ = { }
114
+ runner = evaluate ( entry )
115
115
// On subsequent renders, __VUE_SSR_CONTEXT__ will not be avaialbe
116
116
// to prevent cross-request pollution.
117
- delete sharedContext . __VUE_SSR_CONTEXT__
117
+ delete global . __VUE_SSR_CONTEXT__
118
118
if ( typeof runner !== 'function' ) {
119
119
throw new Error (
120
120
'bundle export should be a function when using ' +
0 commit comments