Files
DECNET/decnet_web/src/routePrefetch.ts
anti f2b3393669 chore: relicense to AGPL-3.0-or-later and add SPDX headers
Replaces LICENSE (GPLv3 -> AGPLv3) and prepends
`SPDX-License-Identifier: AGPL-3.0-or-later` to every source file
across decnet/, decnet_web/, tests/, scripts/, and tools/.

Rationale: closes the GPLv3 ASP loophole so any party operating a
modified DECNET as a network service must offer their modified
source. Personal copyright (Samuel Paschuan) + inbound=outbound
contributions make a future unilateral relicense infeasible.

- LICENSE: full AGPL-3.0 text (gnu.org/licenses/agpl-3.0.txt)
- COPYRIGHT: project copyright notice
- tools/add_spdx_headers.py: idempotent header injector
  (shebang- and PEP 263-aware)

Touches 1565 source files (.py, .ts, .tsx, .js, .jsx, .css, .sh).
No behavior change; comments only.
2026-05-22 21:04:16 -04:00

42 lines
1.7 KiB
TypeScript

// SPDX-License-Identifier: AGPL-3.0-or-later
/* Prefetch-on-intent for lazy-loaded routes.
*
* Each key is a route path; each value is the same dynamic import()
* used by React.lazy() in App.tsx. The bundler dedups by specifier
* string, so a hover-triggered import here warms the exact chunk
* React.lazy resolves on click — no double fetch, no separate chunk.
*
* A Set of already-fired paths prevents redundant imports on repeat
* hovers; the module cache would short-circuit anyway, but skipping
* the call avoids a microtask and makes intent obvious in devtools. */
type Loader = () => Promise<unknown>;
const loaders: Record<string, Loader> = {
'/fleet': () => import('./components/DeckyFleet'),
'/mazenet': () => import('./components/MazeNET/MazeNET'),
'/topologies': () => import('./components/TopologyList/TopologyList'),
'/live-logs': () => import('./components/LiveLogs'),
'/webhooks': () => import('./components/Webhooks'),
'/bounty': () => import('./components/Bounty'),
'/attackers': () => import('./components/Attackers'),
'/config': () => import('./components/Config'),
'/swarm-updates': () => import('./components/RemoteUpdates'),
'/swarm/hosts': () => import('./components/SwarmHosts'),
'/orchestrator': () => import('./components/Orchestrator'),
};
const fired = new Set<string>();
export function prefetchRoute(path: string): void {
const loader = loaders[path];
if (!loader || fired.has(path)) return;
fired.add(path);
loader().catch(() => {
// Network hiccup on a speculative prefetch is a non-event —
// React.lazy will re-try on actual navigation and surface the
// real error there if it persists.
fired.delete(path);
});
}