Skip to content

Commit

Permalink
Merge pull request #12966 from storybookjs/no-progress-in-static-builds
Browse files Browse the repository at this point in the history
UI: Don't listen for progress updates in static builds
  • Loading branch information
shilman authored Nov 1, 2020
2 parents caae314 + 2d19e2c commit 6e52d2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/components/src/Loader/Loader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventSource } from 'global';
import { EventSource, CONFIG_TYPE } from 'global';
import React, { ComponentProps, FunctionComponent, useEffect, useState } from 'react';
import { styled, keyframes } from '@storybook/theming';
import { Icons } from '../icon/icon';
Expand Down Expand Up @@ -157,8 +157,12 @@ export const Loader: FunctionComponent<ComponentProps<typeof PureLoader>> = (pro
const [error, setError] = useState(undefined);

useEffect(() => {
// Don't listen for progress updates in static builds
if (CONFIG_TYPE !== 'DEVELOPMENT') return undefined;

const eventSource = new EventSource('/progress');
let lastProgress: Progress;

eventSource.onmessage = (event: any) => {
try {
lastProgress = JSON.parse(event.data);
Expand All @@ -168,10 +172,12 @@ export const Loader: FunctionComponent<ComponentProps<typeof PureLoader>> = (pro
eventSource.close();
}
};

eventSource.onerror = () => {
if (lastProgress?.value !== 1) setError(new Error('Connection closed'));
if (lastProgress && lastProgress.value !== 1) setError(new Error('Connection closed'));
eventSource.close();
};

return () => eventSource.close();
}, []);

Expand Down
1 change: 1 addition & 0 deletions lib/core/src/server/manager/manager-webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default async ({
version,
dlls: uiDll ? ['./sb_dll/storybook_ui_dll.js'] : [],
globals: {
CONFIG_TYPE: configType,
LOGLEVEL: logLevel,
VERSIONCHECK: JSON.stringify(versionCheck),
RELEASE_NOTES_DATA: JSON.stringify(releaseNotesData),
Expand Down

0 comments on commit 6e52d2e

Please sign in to comment.