From e17c84882f763ceb34a046200de50ffed0f4b776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Wed, 3 Aug 2022 17:00:50 +0200 Subject: [PATCH] Reduce pwa consumption --- site/.gitignore | 4 +- site/scripts/utils.js | 1 + site/source/App.tsx | 62 ++++++++++++------- site/source/api/commune.ts | 10 ++- site/source/components/layout/NewsBanner.tsx | 29 +++++++-- site/source/hooks/useFetchData.ts | 37 +++++++++++ site/source/pages/Nouveautes/Nouveautes.tsx | 27 +++----- site/source/pages/Offline.tsx | 20 ++++++ .../pages/Stats/DemandesUtilisateurs.tsx | 9 ++- site/source/pages/Stats/Stats.tsx | 31 ++++++---- site/source/pages/integration/index.tsx | 7 ++- .../{ => public}/data/versement-mobilité.json | 0 site/source/sw.ts | 29 +++++++-- site/tsconfig.json | 3 +- site/vite-pwa-options.ts | 48 ++++++++++++++ site/vite.config.ts | 58 +++++------------ 16 files changed, 260 insertions(+), 115 deletions(-) create mode 100644 site/source/hooks/useFetchData.ts create mode 100644 site/source/pages/Offline.tsx rename site/source/{ => public}/data/versement-mobilité.json (100%) create mode 100644 site/vite-pwa-options.ts diff --git a/site/.gitignore b/site/.gitignore index 4cc84f862..92d79a677 100644 --- a/site/.gitignore +++ b/site/.gitignore @@ -1,6 +1,6 @@ .env -source/data/* -!source/data/versement-mobilité.json +source/public/data/* +!source/public/data/versement-mobilité.json cypress/videos cypress/screenshots cypress/downloads diff --git a/site/scripts/utils.js b/site/scripts/utils.js index ac327fcaa..6838f2a38 100644 --- a/site/scripts/utils.js +++ b/site/scripts/utils.js @@ -7,6 +7,7 @@ const dataDir = join( '..', '..', 'source', + 'public', 'data' ) diff --git a/site/source/App.tsx b/site/source/App.tsx index 8bf3f866b..7587bf1ba 100644 --- a/site/source/App.tsx +++ b/site/source/App.tsx @@ -15,8 +15,10 @@ import { configSituationSelector, situationSelector, } from '@/selectors/simulationSelectors' +import { ErrorBoundary } from '@sentry/react' +import { FallbackRender } from '@sentry/react/types/errorboundary' import rules from 'modele-social' -import { StrictMode, useContext, useMemo } from 'react' +import { ComponentProps, StrictMode, useContext, useMemo } from 'react' import { Helmet } from 'react-helmet-async' import { useTranslation } from 'react-i18next' import { useSelector } from 'react-redux' @@ -34,6 +36,7 @@ import Iframes from './pages/Iframes' import Integration from './pages/integration/index' import Landing from './pages/Landing/Landing' import Nouveautés from './pages/Nouveautes/Nouveautes' +import Offline from './pages/Offline' import Simulateurs from './pages/Simulateurs' import Stats from './pages/Stats/LazyStats' import Provider, { ProviderProps } from './Provider' @@ -106,6 +109,14 @@ const Router = () => { ) } +const CatchOffline = ({ error }: ComponentProps) => { + if (error.message.includes('Failed to fetch dynamically imported module')) { + return + } else { + throw error + } +} + const App = () => { const { t } = useTranslation() const sitePaths = useContext(SitePathsContext) @@ -119,32 +130,35 @@ const App = () => { /> - {/* Passing location down to prevent update blocking */} - - - - - - - - - - + + {/* Passing location down to prevent update blocking */} + + + + + + + + + + - - + + - - - + + + + + {!isEmbedded &&