diff --git a/lib/components/src/Loader/Loader.tsx b/lib/components/src/Loader/Loader.tsx index 912d5a3c448a..ed61595a0917 100644 --- a/lib/components/src/Loader/Loader.tsx +++ b/lib/components/src/Loader/Loader.tsx @@ -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'; @@ -157,8 +157,12 @@ export const Loader: FunctionComponent> = (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); @@ -168,10 +172,12 @@ export const Loader: FunctionComponent> = (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(); }, []); diff --git a/lib/core/src/server/manager/manager-webpack.config.js b/lib/core/src/server/manager/manager-webpack.config.js index 9d19799ef02e..09d98f874586 100644 --- a/lib/core/src/server/manager/manager-webpack.config.js +++ b/lib/core/src/server/manager/manager-webpack.config.js @@ -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),