From 2d19e2cca06e26b82628d27ff23932a3f5a577c9 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Sat, 31 Oct 2020 11:59:15 +0100 Subject: [PATCH] Don't listen for progress updates in static builds. --- lib/components/src/Loader/Loader.tsx | 10 ++++++++-- lib/core/src/server/manager/manager-webpack.config.js | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) 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),