Skip to content

Commit 37bea9e

Browse files
authored
Reset URL after module change in module view (codesandbox#316)
1 parent 327ffcb commit 37bea9e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/app/src/app/components/sandbox/Preview/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ export default class Preview extends React.PureComponent<Props, State> {
280280
} else {
281281
const renderedModule = this.getRenderedModule();
282282

283+
if (!isInProjectView) {
284+
this.evaluateInSandbox(`history.pushState({}, null, '/')`);
285+
}
286+
283287
this.sendMessage({
284288
type: 'compile',
285289
module: renderedModule,

packages/app/src/sandbox/compile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ async function compile({
150150
document.body.innerHTML = html;
151151

152152
const tt = Date.now();
153+
const oldHTML = document.body.innerHTML;
153154
const evalled = manager.evaluateModule(managerModuleToTranspile);
154155
debug(`Evaluation time: ${Date.now() - tt}ms`);
155-
156-
const domChanged = document.body.innerHTML !== html;
156+
const domChanged = oldHTML !== document.body.innerHTML;
157157

158158
if (isModuleView && !domChanged && !module.title.endsWith('.html')) {
159159
const isReact = module.code && module.code.includes('React');

0 commit comments

Comments
 (0)