Configure base paths and code splitting
Public paths are not local paths
When an app is hosted at https://example.test/workbench/, its public base should match that path. The build tool rewrites supported imported assets and HTML references. Files in the public directory are copied without transformation; runtime-built public paths should respect import.meta.env.BASE_URL. A filesystem alias such as @/components does not set the deployment path, and the router needs its own matching base configuration if using history routing.
// A deliberately narrow helper for trusted public-file names in this app.export function publicAsset(base, file) { if (typeof base !== 'string' || !/^\/(?:[A-Za-z0-9_-]+\/)*$/.test(base)) throw new Error('Expected absolute directory base'); if (typeof file !== 'string' || !/^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)+$/.test(file)) throw new Error('Expected a simple filename'); return base + file;}For example publicAsset("/workbench/", "bench.svg") returns /workbench/bench.svg. This helper intentionally rejects relative bases, absolute external URLs and nested file paths. It is not a universal URL sanitizer. Prefer imported assets for hashing and dependency tracking; use public/bench.svg for a deliberately stable filename. CSS modules and ordinary CSS are handled by the build tool; check generated styles and asset URLs in the target version.
Load a report only when requested
Use a dynamic import for a feature that is not needed immediately. React lazy expects a Promise resolving to a module with a default component export. Define it at module scope so its identity is stable. Suspense can show fallback content while loading; a rejected module load needs an Error Boundary, not just Suspense. This example is source for a staged local app, with a manual acceptance plan. The exact chunk count depends on bundler optimizations.
import React, {lazy, Suspense, useState} from 'react';import {publicAsset} from './asset.mjs';import './workbench.css';const Report = lazy(() => import('./Report.tsx'));export default function App() { const [open, setOpen] = useState(false); return <main><h1>Workbench inventory</h1> <img src={publicAsset(import.meta.env.BASE_URL, 'bench.svg')} alt="Illustration of a workbench" width={160} height={80}/> <button type="button" onClick={() => setOpen(v => !v)}>{open ? 'Hide report' : 'Show report'}</button> {open && <Suspense fallback={<p role="status">Loading report</p>}><Report/></Suspense>} </main>;}import React from 'react';export default function Report() { return <section aria-label="Inventory report"><h2>Inventory report</h2><p>12 tools inspected.</p></section>;}Initially the user sees the workbench image and Show report button. Clicking the button requests the lazy component; a slow load may show Loading report before the report appears. Closing the report hides it; the loaded module can remain cached. This is a staged expectation, not a measured network trace. Avoid loading every dependency dynamically: excessive chunks can create latency and complicate error recovery.
Validate the deployed path
Serve a reviewed build at its configured base on loopback. Inspect the document and request paths; click the report and confirm the chunk returns JavaScript rather than HTML. If adding a history router, refresh a deep link such as /workbench/reports and configure the host to return the SPA entry for app routes, not missing asset requests. Missing scripts should remain errors, not successful HTML responses. Keep hashed assets from the prior release available during a safe rollout; do not endlessly reload on chunk failure. Practice with a deliberately missing synthetic chunk and describe the recovery UI. Actual routing and bundling are pending.