Commit 42d17a8
perf(hls): lazy-load hls.js so the chunk loads only when a tile mounts
hls.js is ~509 KB / ~157 KB gzip. Before this change ``HlsPlayer.jsx``
imported it statically at module top, so any route whose chunk pulled
in HlsPlayer (DashboardPage via CameraCard, plus TestHlsPage) paid the
full gzip cost as part of route resolution — even if the user had zero
cameras and never rendered a tile.
Move the import inside ``setupHls()`` (the existing async function in
the player's main useEffect). The module-level dependency is gone, so
the hls.js chunk no longer rides along with /dashboard's first paint.
It now downloads on the first ``HlsPlayer`` mount; the browser caches
it for the rest of the session.
Race handling: the useEffect cleanup flips a local ``cancelled`` flag
that the post-await branch checks before instantiating Hls. Without
this, navigating away from /dashboard while the chunk is still in
flight would leak an orphaned Hls instance.
Build numbers (1080p, prod build, gzip):
Before: /dashboard first paint = ~726 KB JS (index 62 + dashboard 6 +
player 2 + hls 157 ≈ 727)
After: /dashboard first paint = ~221 KB JS (index 62 + dashboard 6 +
player 2 + preload-helper 1)
hls 157 KB loads async on first tile
Phase 2 item #3 from the tech-debt audit. No behaviour change for
end users beyond the perf win — same player code, same player events,
same Clerk-JWT xhrSetup.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 48e6183 commit 42d17a8
1 file changed
Lines changed: 25 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
5 | 11 | | |
6 | 12 | | |
7 | 13 | | |
| |||
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
37 | 50 | | |
38 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
39 | 60 | | |
40 | 61 | | |
41 | 62 | | |
| |||
189 | 210 | | |
190 | 211 | | |
191 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
192 | 216 | | |
193 | 217 | | |
194 | 218 | | |
| |||
0 commit comments