diff --git a/app/components/Sidebar/components/Collections.js b/app/components/Sidebar/components/Collections.js index 97141b084a..b2ce303ab9 100644 --- a/app/components/Sidebar/components/Collections.js +++ b/app/components/Sidebar/components/Collections.js @@ -20,6 +20,7 @@ type Props = { function Collections({ onCreateCollection }: Props) { const [isFetching, setFetching] = React.useState(false); + const [fetchError, setFetchError] = React.useState(); const { ui, policies, documents, collections } = useStores(); const isPreloaded: boolean = !!collections.orderedData.length; const { t } = useTranslation(); @@ -32,17 +33,25 @@ function Collections({ onCreateCollection }: Props) { React.useEffect(() => { async function load() { - if (!collections.isLoaded && !isFetching) { + if (!collections.isLoaded && !isFetching && !fetchError) { try { setFetching(true); await collections.fetchPage({ limit: 100 }); + } catch (error) { + ui.showToast( + t("Collections could not be loaded, please reload the app"), + { + type: "error", + } + ); + setFetchError(error); } finally { setFetching(false); } } } load(); - }, [collections, isFetching]); + }, [collections, isFetching, ui, fetchError, t]); const [{ isCollectionDropping }, dropToReorderCollection] = useDrop({ accept: "collection", @@ -92,7 +101,7 @@ function Collections({ onCreateCollection }: Props) { ); - if (!collections.isLoaded) { + if (!collections.isLoaded || fetchError) { return (
{t("Collections")}
diff --git a/app/hooks/useMediaQuery.js b/app/hooks/useMediaQuery.js index 4fcdc74a59..1280f7d3e7 100644 --- a/app/hooks/useMediaQuery.js +++ b/app/hooks/useMediaQuery.js @@ -5,15 +5,17 @@ export default function useMediaQuery(query: string): boolean { const [matches, setMatches] = useState(false); useEffect(() => { - const media = window.matchMedia(query); - if (media.matches !== matches) { - setMatches(media.matches); + if (window.matchMedia) { + const media = window.matchMedia(query); + if (media.matches !== matches) { + setMatches(media.matches); + } + const listener = () => { + setMatches(media.matches); + }; + media.addListener(listener); + return () => media.removeListener(listener); } - const listener = () => { - setMatches(media.matches); - }; - media.addListener(listener); - return () => media.removeListener(listener); }, [matches, query]); return matches; diff --git a/app/index.js b/app/index.js index cec7c16cc3..da02a5a7f3 100644 --- a/app/index.js +++ b/app/index.js @@ -79,7 +79,7 @@ window.addEventListener("load", async () => { if (!env.GOOGLE_ANALYTICS_ID || !window.ga) return; // https://github.com/googleanalytics/autotrack/issues/137#issuecomment-305890099 - await import(/** webpackChunkName "autotrack" */ "autotrack/autotrack.js"); + await import(/** webpackChunkName: "autotrack" */ "autotrack/autotrack.js"); window.ga("require", "outboundLinkTracker"); window.ga("require", "urlChangeTracker"); diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 7306ee1c81..65b469d65e 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -109,6 +109,7 @@ "Dismiss": "Dismiss", "Keyboard shortcuts": "Keyboard shortcuts", "Back": "Back", + "Collections could not be loaded, please reload the app": "Collections could not be loaded, please reload the app", "New collection": "New collection", "Collections": "Collections", "Untitled": "Untitled", diff --git a/webpack.config.js b/webpack.config.js index 7bc65d0aab..f5f8785d18 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -97,6 +97,7 @@ module.exports = { optimization: { runtimeChunk: 'single', moduleIds: 'hashed', + chunkIds: 'named', splitChunks: { cacheGroups: { vendor: {