Skip to content

Commit

Permalink
Save the preview frame URL as the story changes.
Browse files Browse the repository at this point in the history
Sometimes when there are problems with HMR, we end up doing a
hard-reload of the preview iframe, whilst leaving the main window.

As the preview iframe didn't change its URL ever, this led to problems
where the old (usually original) story was loaded in such circumstances.

See #614 and #1328
  • Loading branch information
tmeasday committed Nov 22, 2017
1 parent 462a8d9 commit 6638f5c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/angular/src/client/preview/init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import keyEvents from '@storybook/ui/dist/libs/key_events';
import qs from 'qs';

import { selectStory } from './actions';

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

// Keep whichever of these are set that we don't override when stories change
const originalQueryParams = queryParams;
reduxStore.subscribe(() => {
const { selectedKind, selectedStory } = reduxStore.getState();

const queryString = qs.stringify({
...originalQueryParams,
selectedKind,
selectedStory,
});
window.history.pushState({}, '', `?${queryString}`);
});

// Handle keyEvents and pass them to the parent.
window.onkeydown = e => {
const parsedEvent = keyEvents(e);
Expand Down
15 changes: 15 additions & 0 deletions app/react/src/client/preview/init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import keyEvents from '@storybook/ui/dist/libs/key_events';
import qs from 'qs';

import { selectStory } from './actions';

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

// Keep whichever of these are set that we don't override when stories change
const originalQueryParams = queryParams;
reduxStore.subscribe(() => {
const { selectedKind, selectedStory } = reduxStore.getState();

const queryString = qs.stringify({
...originalQueryParams,
selectedKind,
selectedStory,
});
window.history.pushState({}, '', `?${queryString}`);
});

// Handle keyEvents and pass them to the parent.
window.onkeydown = e => {
const parsedEvent = keyEvents(e);
Expand Down
15 changes: 15 additions & 0 deletions app/vue/src/client/preview/init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import keyEvents from '@storybook/ui/dist/libs/key_events';
import qs from 'qs';

import { selectStory } from './actions';

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

// Keep whichever of these are set that we don't override when stories change
const originalQueryParams = queryParams;
reduxStore.subscribe(() => {
const { selectedKind, selectedStory } = reduxStore.getState();

const queryString = qs.stringify({
...originalQueryParams,
selectedKind,
selectedStory,
});
window.history.pushState({}, '', `?${queryString}`);
});

// Handle keyEvents and pass them to the parent.
window.onkeydown = e => {
const parsedEvent = keyEvents(e);
Expand Down

0 comments on commit 6638f5c

Please sign in to comment.