Skip to content

Commit 866ba73

Browse files
arthurdennerCompuIves
authored andcommitted
fix(sandbox): Fixing loading of sandbox when a module is informed but doesn't exist (codesandbox#921)
1 parent 79f5ab4 commit 866ba73

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

packages/app/src/app/store/actions.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,34 @@ export function setUrlOptions({ state, router, utils }) {
3838

3939
if (options.currentModule) {
4040
const sandbox = state.get('editor.currentSandbox');
41-
const module = utils.resolveModule(
42-
options.currentModule,
43-
sandbox.modules,
44-
sandbox.directories,
45-
options.currentModule.directoryShortid
46-
);
4741

48-
if (module) {
49-
state.push('editor.tabs', {
50-
type: 'module',
51-
moduleShortid: module.shortid,
52-
dirty: false,
42+
try {
43+
const module = utils.resolveModule(
44+
options.currentModule,
45+
sandbox.modules,
46+
sandbox.directories,
47+
options.currentModule.directoryShortid
48+
);
49+
50+
if (module) {
51+
state.push('editor.tabs', {
52+
type: 'module',
53+
moduleShortid: module.shortid,
54+
dirty: false,
55+
});
56+
state.set('editor.currentModuleShortid', module.shortid);
57+
}
58+
} catch (err) {
59+
const now = Date.now();
60+
const title = `Could not find the module ${options.currentModule}`;
61+
62+
state.push('notifications', {
63+
title,
64+
id: now,
65+
notificationType: 'warning',
66+
endTime: now + 2000,
67+
buttons: [],
5368
});
54-
state.set('editor.currentModuleShortid', module.shortid);
5569
}
5670
}
5771

0 commit comments

Comments
 (0)