6.5 KiB
PRES-MGMT Session View — Refactor Plan
Goal
Make the Presentation Management Session view deterministic on cold-start (empty IndexedDB). The page must render Presentations, Presenters, and Hosted Files without requiring manual refreshes.
Constraints
- Svelte 5 runes and Dexie
liveQuerybehavior (observable recreation, subscription timing). - Minimize user-perceived latency — keep navigation snappy where possible.
- Avoid large architectural changes unless necessary.
Options (high level)
A) Blocking Hydration (recommended for correctness)
- Block the route
+page.tsload until the session and all directly required related objects are fetched from the backend and written into IndexedDB. Returninitial_session_objin the load data for immediate rendering. - Pros: simplest to guarantee first-draw correctness; minimal component changes.
- Cons: adds latency to navigation (can be mitigated with optimistic UI or progress indicator).
B) Prefetch Related Records + Hydrate Fallback (hybrid)
- Non-blocking load but
+page.tsreturnsinitial_session_objand small related-objects payloads (presentations, presenter IDs, hosted_file metadata). Components use these fallbacks whileliveQuerytakes over. - Pros: keeps navigation responsive; often sufficient.
- Cons: requires careful payload shaping and DB write ordering.
C) Explicit Dependency Chaining in UI (advanced)
- Keep non-blocking loads and use explicit dependency chaining: write session -> await write completion -> then write presentations -> await -> then presenters, ensuring microtask queue flushes between writes. Use targeted
liveQueryre-creation only when upstream dependency fully resolved. - Pros: minimal route latency; deterministic ordering.
- Cons: more complex to implement and test.
Recommendation
Start with Option A (Blocking Hydration) for the session page to restore deterministic behavior quickly. After correctness is achieved, consider converting to Option B or C for improved perceived performance if needed.
Detailed Steps (Option A - Blocking Hydration)
-
Add a small helper in
events_func(e.g.,load_session_with_relations) that:- fetches session by ID from API
- fetches related presentations (limit/filters as needed)
- fetches presenters referenced by those presentations (deduplicate IDs)
- fetches hosted_file metadata for presentation files (if required for the view)
- writes all results to IndexedDB in a controlled order (session -> presentations -> presenters -> hosted_files)
- returns a compact
initial_session_objpayload containing fields needed for first-draw (session, presentation list, presenter summary)
Implementation note: Use
await db.transaction('rw', db_events.session, db_events.presentation, db_events.presenter, async () => {...})if atomicity helps. Alternatively write in sequential awaits and callawait Promise.resolve()after each write to let the microtask queue settle. -
Update route loader:
src/routes/events/[event_id]/(pres_mgmt)/session/[session_id]/+page.ts(create if missing) to call andawaitthe helper, then returninitial_session_objondata.Example pseudo-code:
export async function load({ params, parent }) { const data = await parent(); if (browser) { const init = await events_func.load_session_with_relations({ api_cfg: data[data.account_id].api, session_id: params.session_id, log_lvl: 0 }); data.initial_session_obj = init; } return data; }
-
Ensure the page component
+page.svelteuses theinitial_session_objas immediate fallback (it already does in Aether). -
Add instrumentation logs inside
liveQueryclosures and the helper to verify ordering during QA. -
Add tests (see below) and manual verification steps.
Alternative (Option B - Hybrid) Implementation Notes
- If you cannot block the route, return an
initial_session_objthat includes minimal related object arrays (IDs + small metadata) and have+page.sveltewrite those into IDB before mounting heavy child components. - Use
untrack()to set selection IDs so stores are updated without causing premature reactivity loops.
Explicit Dependency Chaining (Option C) Notes
- Implement a single
prefetchfunction that sequentially performs writes andawait Promise.resolve()between stages. - For debugging, add microtask delays (e.g.,
await 0) between writes to observe behaviour.
Testing and Verification
-
Integration test (Playwright recommended)
- Clear IndexedDB for the app origin.
- Navigate to
/events/<event_id>/.../session/<session_id>and assert that the presentation list and presenters are visible within N ms without manual refresh. - Repeat on subsequent navigations to ensure no regressions.
-
Unit tests
- For
events_func.load_session_with_relations, stub API responses and assert DB writes are made in expected order.
- For
-
Manual QA
- With a cold profile or after clearing Site storage, navigate to the session page and confirm content is present after the initial navigation and that no manual refreshes are required.
Migration and Rollout
- Implement Option A behind a feature flag if you want to control rollout.
- Short-term: apply Option A to the single problematic route to reduce blast radius.
- Long-term: consider a library-level helper to standardize "blocking prefetch for nested related records" across other pages.
Rollback Plan
- Because changes are additive and limited to one route and helper, revert the
+page.tsmodification and helper call to restore prior behavior.
Deliverables for tomorrow
events_func.load_session_with_relationshelper (TS) + unit tests- Updated
+page.tsloader for session route toawaithelper and returninitial_session_obj - Small test harness / Playwright test that reproduces the cold-start issue and verifies the fix
- Instrumentation logs temporarily enabled for QA
Estimated effort
- Blocking hydration implementation + tests: 2-4 hours
- Hybrid or chaining implementations: additional 2-6 hours depending on thoroughness
Notes about Svelte 5 + Dexie specifics
- Keep
liveQueryclosures stable; capture primitive IDs rather than reactive objects. - Use
$derivedand$derived.byto keep observable instances stable across renders. - Use
untrack()when setting selection values to avoid premature subscriptions. - After DB writes, allowing the microtask queue to settle (
await Promise.resolve()) helps ensure observers are notified in the expected order during development and debugging.
If you want I can implement Option A for the session route tomorrow (create helper, update loader, add test).