Skip to content

Commit e4ce2a0

Browse files
Fix refresh for hash based URL in Preview (codesandbox#3881)
* fix(Preview): dispatch 'refresh' for hashed based URL * refactor(preview): rename hashedURL method * refactor(preview): use early return in hash URL handler
1 parent 42df2e2 commit e4ce2a0

File tree

1 file changed

+14
-1
lines changed
  • packages/common/src/components/Preview

1 file changed

+14
-1
lines changed

packages/common/src/components/Preview/index.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@ class BasePreview extends React.Component<Props, State> {
487487
back: false,
488488
forward: false,
489489
});
490+
491+
this.refreshHashedUrl(urlInAddressBar);
490492
}
491493
};
492494

@@ -497,7 +499,10 @@ class BasePreview extends React.Component<Props, State> {
497499
const urlToSet = urlInAddressBar || url;
498500

499501
if (this.element) {
500-
this.element.src = urlToSet || this.currentUrl();
502+
const iframeSRC = urlToSet || this.currentUrl();
503+
this.element.src = iframeSRC;
504+
505+
this.refreshHashedUrl(iframeSRC);
501506
}
502507

503508
this.setState({
@@ -507,6 +512,14 @@ class BasePreview extends React.Component<Props, State> {
507512
});
508513
};
509514

515+
refreshHashedUrl = url => {
516+
if (!url.includes('#')) {
517+
return;
518+
}
519+
520+
dispatch({ type: 'refresh' });
521+
};
522+
510523
handleBack = () => {
511524
dispatch({
512525
type: 'urlback',

0 commit comments

Comments
 (0)