Skip to content

Commit

Permalink
fix: fix snapshot eval code with window context
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw committed Sep 17, 2021
1 parent 3b44114 commit af21766
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/runtime/browser-snapshot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ export function GarfishBrowserSnapshot(op?: BrowserConfig) {
openBrowser: false,
afterLoad(appInfo, appInstance) {
const sandboxConfig = appInfo.sandbox || Garfish?.options?.sandbox;
if (sandboxConfig === false || sandboxConfig.open === false)
if (
sandboxConfig === false ||
sandboxConfig.open === false ||
sandboxConfig?.snapshot === false
) {
config.open = false;
}
if (sandboxConfig) {
config.open = sandboxConfig?.open && sandboxConfig?.snapshot === true;
config.protectVariable = [
...(Garfish?.options.protectVariable || []),
...(appInfo.protectVariable || []),
Expand Down
8 changes: 8 additions & 0 deletions packages/runtime/core/src/module/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ export class App {
options.async,
);
code += url ? `\n//# sourceURL=${url}\n` : '';

if (!env['window']) {
env = {
window: this.global,
...env,
};
}

evalWithEnv(`;${code}`, env);
revertCurrentScript();
}
Expand Down

0 comments on commit af21766

Please sign in to comment.