aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/tests/test_first_load_is_lean.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-09-25 10:47:37 +0200
committerChristophe Besson <cbesson@gmail.com>2026-09-25 10:47:37 +0200
commit0bdce359c0bf19fa98f1b7f9975be32704abe1f0 (patch)
treec67c24b9751c3d8063fc9806a5d6650a3b8c03fb /packages/meshbay-hub/tests/test_first_load_is_lean.py
parent950f4aa6d107e127fb6dc0579beedbff0e6f1af5 (diff)
downloadmeshbay-0bdce359c0bf19fa98f1b7f9975be32704abe1f0.tar.gz
feat(client): fetch the media apps, the player, settings and search on first use
apps.js registers Videos, Music, Photos and every settings pane through lazy.js; the group page does the same for the video player and the settings panel, and the shell for the search page. The first download goes from 49 modules / 386 KB gzip to 37 / 289 KB; opening Music now fetches music-app.js and media-tiles.js and nothing of Videos. test_first_load_is_lean holds the eager graph; test_spa_imports checks that every on-demand load names an export that exists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-hub/tests/test_first_load_is_lean.py')
-rw-r--r--packages/meshbay-hub/tests/test_first_load_is_lean.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/packages/meshbay-hub/tests/test_first_load_is_lean.py b/packages/meshbay-hub/tests/test_first_load_is_lean.py
new file mode 100644
index 0000000..74cd880
--- /dev/null
+++ b/packages/meshbay-hub/tests/test_first_load_is_lean.py
@@ -0,0 +1,54 @@
+"""
+What a browser downloads before the first screen renders.
+
+ES modules load their static `import` graph up front, whether the visitor opens
+what it leads to or not. The Videos, Music and Photos apps, the video player,
+the group settings and the search page used to be part of it — about a quarter
+of the client, paid by a member who only opens the chat. They are now fetched
+the first time they are shown (lazy.js); one static import added back anywhere
+on the path from app.js would quietly undo that, and nothing else would fail.
+"""
+
+import re
+from pathlib import Path
+
+STATIC = Path(__file__).resolve().parents[1] / "src" / "meshbay_hub" / "static"
+
+STATIC_IMPORT = re.compile(
+ r"""^\s*(?:import|export)\b[^'";]*?\bfrom\s*['"]\./([^'"]+)['"]"""
+ r"""|^\s*import\s*['"]\./([^'"]+)['"]""", re.M)
+
+# Loaded on demand, never at start-up.
+ON_DEMAND = {
+ "video-app.js", "music-app.js", "photos-app.js", "helloworld-app.js",
+ "chat-app-settings.js", "video-app-settings.js", "music-app-settings.js",
+ "photos-app-settings.js", "helloworld-app-settings.js",
+ "video-player.js", "group-settings.js", "search-page.js",
+}
+
+
+def _eager() -> set[str]:
+ seen, stack = set(), ["app.js"]
+ while stack:
+ name = stack.pop()
+ if name in seen or not (STATIC / name).exists():
+ continue
+ seen.add(name)
+ text = (STATIC / name).read_text(encoding="utf-8")
+ stack += [a or b for a, b in STATIC_IMPORT.findall(text)]
+ return seen
+
+
+def test_the_first_download_leaves_the_apps_out():
+ eager = _eager()
+ assert len(eager) > 20, "the import graph was not followed — re-read this test"
+ brought_back = sorted(eager & ON_DEMAND)
+ assert not brought_back, (
+ f"loaded at start-up again: {brought_back} — a static import on the "
+ f"path from app.js; import it through lazy.js instead")
+
+
+def test_every_module_loaded_on_demand_still_exists():
+ """A rename would make the check above pass for a file nobody serves."""
+ missing = sorted(n for n in ON_DEMAND if not (STATIC / n).exists())
+ assert not missing, missing