Skip to content

Commit 776f3a6

Browse files
authored
Merge pull request #2349 from storybooks/1328-fix-hmr-failure
Save the preview frame URL as the story changes.
2 parents 462a8d9 + 6638f5c commit 776f3a6

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

app/angular/src/client/preview/init.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import keyEvents from '@storybook/ui/dist/libs/key_events';
2+
import qs from 'qs';
3+
24
import { selectStory } from './actions';
35

46
export default function(context) {
@@ -8,6 +10,19 @@ export default function(context) {
810
reduxStore.dispatch(selectStory(queryParams.selectedKind, queryParams.selectedStory));
911
}
1012

13+
// Keep whichever of these are set that we don't override when stories change
14+
const originalQueryParams = queryParams;
15+
reduxStore.subscribe(() => {
16+
const { selectedKind, selectedStory } = reduxStore.getState();
17+
18+
const queryString = qs.stringify({
19+
...originalQueryParams,
20+
selectedKind,
21+
selectedStory,
22+
});
23+
window.history.pushState({}, '', `?${queryString}`);
24+
});
25+
1126
// Handle keyEvents and pass them to the parent.
1227
window.onkeydown = e => {
1328
const parsedEvent = keyEvents(e);

app/react/src/client/preview/init.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import keyEvents from '@storybook/ui/dist/libs/key_events';
2+
import qs from 'qs';
3+
24
import { selectStory } from './actions';
35

46
export default function(context) {
@@ -8,6 +10,19 @@ export default function(context) {
810
reduxStore.dispatch(selectStory(queryParams.selectedKind, queryParams.selectedStory));
911
}
1012

13+
// Keep whichever of these are set that we don't override when stories change
14+
const originalQueryParams = queryParams;
15+
reduxStore.subscribe(() => {
16+
const { selectedKind, selectedStory } = reduxStore.getState();
17+
18+
const queryString = qs.stringify({
19+
...originalQueryParams,
20+
selectedKind,
21+
selectedStory,
22+
});
23+
window.history.pushState({}, '', `?${queryString}`);
24+
});
25+
1126
// Handle keyEvents and pass them to the parent.
1227
window.onkeydown = e => {
1328
const parsedEvent = keyEvents(e);

app/vue/src/client/preview/init.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import keyEvents from '@storybook/ui/dist/libs/key_events';
2+
import qs from 'qs';
3+
24
import { selectStory } from './actions';
35

46
export default function(context) {
@@ -8,6 +10,19 @@ export default function(context) {
810
reduxStore.dispatch(selectStory(queryParams.selectedKind, queryParams.selectedStory));
911
}
1012

13+
// Keep whichever of these are set that we don't override when stories change
14+
const originalQueryParams = queryParams;
15+
reduxStore.subscribe(() => {
16+
const { selectedKind, selectedStory } = reduxStore.getState();
17+
18+
const queryString = qs.stringify({
19+
...originalQueryParams,
20+
selectedKind,
21+
selectedStory,
22+
});
23+
window.history.pushState({}, '', `?${queryString}`);
24+
});
25+
1126
// Handle keyEvents and pass them to the parent.
1227
window.onkeydown = e => {
1328
const parsedEvent = keyEvents(e);

0 commit comments

Comments
 (0)