mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
c9dfe9c688
After an update, a tab or a device whose service worker still serves the previous build asks for chunks the update removed. The server answered those requests with index.html and a 200, so the import failed with a MIME error, and everything caching in between was free to keep the HTML as the chunk. A precache install that met a missing file stored it, and Workbox reuses hashed entries by URL, so the device showed "A new version is available" on every load, whatever the reload or the cleared browser cache, and carried the broken entry into every later release that keeps the file's name. The SPA fallback now answers a GET for a build file that is not on disk with a plain 404 (no-store) instead of index.html. A precache install refuses it, so the worker whose cache is complete stays in charge until the new build is. index.html is sent relative to the public dir, which also stops an install living under a dot directory from answering every deep link with a 404. On the client, the reload after a dead chunk (the automatic one and the button on the update screen) no longer goes straight back to the worker that served the broken shell. When that same worker is still in charge and the server answers, its precache and registration are dropped first, so the reload reaches the build the server runs now. Offline, and in offline mode, the shell is kept. Every recovery reload, and the reload of the version handover, asks for the page under a one-off query parameter, so a proxy or CDN that keeps index.html against its headers cannot hand back the stale shell either. A chunk the entry imports statically fails before any of that code runs. shell-guard.js, a small classic script loaded ahead of the entry, watches for exactly that failure and runs the same recovery, once per session. A stylesheet, font or icon that holds a page raises no error at all, so once the app has started and the browser is idle, it looks through the precache for entries that hold a page under a build file's name, fetches each from the server past every cache and puts it back in place. A repaired stylesheet is loaded again, and so are the app's stylesheets when a font was repaired, since the browser does not try a face that failed again in the same document. Only the headers are read, a precache found sound is not looked at again until its entries change, nothing is fetched while nothing is broken, and nothing happens offline, in offline mode or without storage. An answer that is not the file (an auth wall, its login page, a server error) leaves the entry for the next launch. A page the recovery loaded from the network already runs the version the server reports, so the version handover now records it instead of reloading it a second time once the new worker takes over. A page loaded past an older worker that is still in charge, as a hard reload does, still asks for the new worker and records the version only once that has taken over, so the next tab or launch cannot get the old shell without a handover. Dropping the worker ends a Web Push subscription with it, so on such a device the settings card shows push as off until it is switched on again. A missing sw-push.js now fails the worker install with a 404 rather than index.html; the comments that described the old answer say so.
63 lines
3.2 KiB
TypeScript
63 lines
3.2 KiB
TypeScript
import React from 'react'
|
|
import ReactDOM from 'react-dom/client'
|
|
import { BrowserRouter } from 'react-router'
|
|
import App from './App'
|
|
// Self-hosted Poppins (bundled, same-origin) so the app font can't be blocked by
|
|
// ad/tracker blockers the way the Google Fonts CDN can.
|
|
import '@fontsource/poppins/300.css'
|
|
import '@fontsource/poppins/400.css'
|
|
import '@fontsource/poppins/500.css'
|
|
import '@fontsource/poppins/600.css'
|
|
import '@fontsource/poppins/700.css'
|
|
// MuseoModerno for the login wordmark — same reasoning, it used to come from the
|
|
// Google Fonts CDN via a render-blocking <link> in index.html.
|
|
import '@fontsource/museomoderno/400.css'
|
|
import '@fontsource/museomoderno/700.css'
|
|
import '@fontsource/museomoderno/800.css'
|
|
// Geist Sans (self-hosted too) — used only for secondary "subtext" via --font-subtext.
|
|
import '@fontsource/geist-sans/400.css'
|
|
import '@fontsource/geist-sans/500.css'
|
|
import '@fontsource/geist-sans/600.css'
|
|
// Leaflet CSS bundled from node_modules instead of unpkg: the service worker
|
|
// cached the CDN stylesheet as an opaque response, which the browser then
|
|
// rejected, breaking the Atlas/trip maps (#1497). Bundling keeps it same-origin
|
|
// and precached with the app shell. Must stay above index.css, which overrides
|
|
// several .leaflet-* styles.
|
|
import 'leaflet/dist/leaflet.css'
|
|
import './index.css'
|
|
// Native HTML5 drag-and-drop never fires on touch input, so the planner's place /
|
|
// day reordering was dead on Android and iOS. The `drag-drop-touch` polyfill synthesises
|
|
// the standard drag events from touch gestures over draggable elements (#1265). It is
|
|
// loaded only on non-mobile viewports: reorder DnD is disabled on mobile (#1432), where
|
|
// the polyfill's synthetic click/dblclick otherwise turned quick one-finger map pans into
|
|
// double-tap zooms (#1440). See utils/touchDragPolyfill.ts.
|
|
import { maybeInstallTouchDragPolyfill } from './utils/touchDragPolyfill'
|
|
import { startConnectivityProbe } from './sync/connectivity'
|
|
import { requestPersistentStorage } from './sync/persistentStorage'
|
|
import ErrorBoundary, { RootErrorFallback } from './components/shared/ErrorBoundary'
|
|
import { installGlobalErrorHandlers } from './utils/globalErrorHandlers'
|
|
import { schedulePrecacheRepair } from './utils/serviceWorkerShell'
|
|
|
|
maybeInstallTouchDragPolyfill()
|
|
startConnectivityProbe()
|
|
// Keep offline data (map tiles, file blobs, IndexedDB) exempt from eviction.
|
|
requestPersistentStorage()
|
|
// Event handlers and async code never reach a boundary; this is where they land.
|
|
installGlobalErrorHandlers()
|
|
// A page the precache keeps under a stylesheet's or a script's name would be
|
|
// handed on to every later release (#2524).
|
|
schedulePrecacheRepair()
|
|
|
|
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
<React.StrictMode>
|
|
<BrowserRouter>
|
|
{/* Outermost net: catches App itself and TranslationProvider, which every
|
|
boundary further in sits below. Its fallback is untranslated on purpose
|
|
— if the provider is the thing that broke, t() would echo raw keys. */}
|
|
<ErrorBoundary boundaryId="root" level="root" fallback={s => <RootErrorFallback {...s} />}>
|
|
<App />
|
|
</ErrorBoundary>
|
|
</BrowserRouter>
|
|
</React.StrictMode>,
|
|
)
|