-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jsx
31 lines (22 loc) · 900 Bytes
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import React from 'react';
import { SET_CURRENT_STORY } from '@storybook/core-events';
import addons from '@storybook/addons';
import { hydrate } from 'react-dom';
import { start } from '@storybook/core/client';
import { getStories, getUrlForStory } from './utils';
let locationChangeInProgress = false;
// check storybook/app/react/src/client/preview/render.tsx if broken
const render = ({ storyFn: StoryFn }) => {
if (locationChangeInProgress) return;
hydrate(<StoryFn />, document.getElementById('root'));
};
const forceServerSideRender = (story) => {
if (story.viewMode !== 'story') return;
locationChangeInProgress = true;
window.location.assign(getUrlForStory(story));
};
const api = start(render);
require('@root/.storybook/preview-ssr');
api.configure(getStories, module, 'react');
const channel = addons.getChannel();
channel.on(SET_CURRENT_STORY, forceServerSideRender);