Repository navigation
refactor(webapp): simplify ResumeRefreshService — delegate visibilitychange to Supabase + replace 12s watchdog with instant reload - #415
Conversation
…lapse pending state Supabase auth-js >= 2.71 ships a native visibilitychange listener that calls the session recovery path on resume. Removes the duplicated visibility + pagehide tracking from ResumeRefreshService. Service now owns only the surfaces the SDK does not cover: pageshow.persisted (bfcache) and document.wasDiscarded (low-memory tab discard), plus Pulpe-specific cache invalidation and userSettings reload. Also collapses #pendingReason + #loadingTimeoutId into a single #pending struct so the watchdog state is set/cleared atomically, and bumps the declared @supabase/supabase-js floor to ^2.56.0 to make the auth-js >= 2.71 requirement explicit (lockfile already at 2.56.0). ~100 lines removed. All 1875 frontend tests still green.
…hung-fetch WebKit silently aborts in-flight fetch on bfcache enter (webkit.org/b/282506). If the user backgrounds the app DURING the initial getSession() call, the Promise never resolves: AuthStore.isLoading stays true forever. Previous implementation queued the resume reason and waited 12s before reloading. That wait was theater — the Promise was already dead, no amount of patience would unblock it. Detect isLoading=true at pageshow and reload immediately. Cooldown (60s sessionStorage) still protects against reload loops. Removes: - effect()-based queue-and-drain - RESUME_LOADING_TIMEOUT_MS (12s) + setTimeout watchdog - #pending struct + #armPending + #drainPendingReasonOnAuthReady - redundant #shouldRefreshOnResume() re-check in #runSoftRefresh - duplicated logger.warn on hung-fetch path (single warn via #triggerHardReload) Adds: - 'pageshow_hung_fetch' to ResumeTriggerReason enum (single source of cause) - two new tests: instant reload on isLoading=true, no-op on non-protected route
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
| if (this.#authStore.isLoading()) { | ||
| this.#triggerHardReload('pageshow_hung_fetch'); | ||
| return; | ||
| } |
There was a problem hiding this comment.
[IMPORTANT] Fausse positive sur wasDiscarded : le check isLoading() s'applique aux deux cas alors que le bug WebKit est bfcache-exclusif (confiance: 82%)
Le hung-fetch est causé par WebKit qui annule silencieusement les fetch() en-vol lors de l'entrée en bfcache (webkit.org/b/282506). Ce bug ne s'applique qu'à event.persisted === true.
Pour un tab discardé (wasDiscarded=true, persisted=false), la page est reconstruite à zéro : isLoading()=true est l'état initial normal, pas un fetch suspendu. Angular bootstrap généralement avant le pageshow (le listener est donc déjà enregistré quand pageshow fire), ce qui signifie que ce chemin est atteignable en production.
Impact : sur un tab discardé sur une route protégée, l'auth démarre normalement (isLoading=true) → le service déclenche un hard reload inutile → la page se recharge une fois (limitée par le cooldown à 60s).
| } | |
| if (event.persisted && this.#authStore.isLoading()) { | |
| this.#triggerHardReload('pageshow_hung_fetch'); | |
| return; | |
| } |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d560bfba7c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (this.#authStore.isLoading()) { | ||
| this.#triggerHardReload('pageshow_hung_fetch'); | ||
| return; |
There was a problem hiding this comment.
Gate hung-fetch reload to bfcache restores only
This hard-reload path now runs whenever isLoading() is true for both pageshow.persisted and document.wasDiscarded resumes, but wasDiscarded restores are cold reloads where auth booting is expected (not the WebKit hung-fetch condition). In that case this causes an unnecessary full reload, and if cooldown blocks it, the resume trigger is dropped entirely. Restricting this branch to the bfcache case (event.persisted) avoids false-positive reloads on discarded-tab restores.
Useful? React with 👍 / 👎.
| if (!event.persisted && !wasDiscarded) { | ||
| return; |
There was a problem hiding this comment.
Preserve app-level refresh on non-bfcache foreground resumes
By removing the visibility/pagehide path, resume refresh now only runs on pageshow persisted/discarded signals. Regular foregrounding (tab/app switch without bfcache/discard) no longer triggers this service, so its app-level recovery work (budget/templates cache invalidation and userSettings reload) is skipped even after long background periods. Supabase’s visibility handler can refresh auth tokens, but it does not execute these Pulpe-specific refresh steps.
Useful? React with 👍 / 👎.
| @@ -130,38 +119,6 @@ describe('ResumeRefreshService', () => { | |||
| expect(reloadSpy).not.toHaveBeenCalled(); | |||
| }); | |||
There was a problem hiding this comment.
[SUGGESTION] Test manquant pour wasDiscarded=true + isLoading=true (confiance: 90%)
Le test existant à la ligne 107 couvre wasDiscarded=true avec isLoading=false (comportement happy path). Mais il n'y a pas de test pour le cas où auth est encore en cours de chargement au moment du pageshow discardé — c'est exactement le scénario de la fausse positive décrite sur le service.
Ajouter ce test permettrait de documenter et verrouiller le comportement attendu (soft refresh vs hard reload) :
it('should perform soft refresh when document was discarded even if auth is still initializing', async () => {
Object.defineProperty(document, 'wasDiscarded', {
configurable: true,
value: true,
});
isLoadingSignal.set(true);
dispatchPageShow(false);
await Promise.resolve();
// wasDiscarded + isLoading=true is NOT a hung-fetch: auth is just starting fresh
expect(reloadSpy).not.toHaveBeenCalled();
expect(mockAuthSession.refreshSession).not.toHaveBeenCalled();
});
Review PR #415Résumé : 0 bloquant - 1 important - 1 suggestion Importants
Suggestions
Points positifs
Verdict : CHANGES REQUESTED |
WebKit silently aborts in-flight fetch on bfcache enter (webkit.org/b/282506) — this affects event.persisted=true only. On document.wasDiscarded=true the page is rebuilt from scratch (cold restart, fresh JS state), so AuthStore.isLoading()=true is the normal initial bootstrap state, not a hung Promise. Split #onPageShow so the hung-fetch failsafe only fires on bfcache. Discarded tabs fall through to the soft refresh path, which self-gates via #hasLiveSession() during bootstrap.
…Doc essays, fix mock asymmetry
Summary
Two-step simplification of
ResumeRefreshService, the iOS Safari bfcache failsafe added in #414.Step 1 — Delegate
visibilitychangeto Supabase auth-js (>= 2.71)The Supabase JS SDK ships a native
visibilitychangelistener (auth-js@2.71.1via@supabase/supabase-js@^2.56.0) that calls the session recovery path on tab foreground. Removed the duplicated visibility + pagehide tracking + 15-min long-background heuristic — Pulpe now only owns the surfaces the SDK does NOT cover:pageshow.persisted(bfcache) anddocument.wasDiscarded(low-memory tab discard).Bumped declared
@supabase/supabase-jsfloor from^2.49.10to^2.56.0to make the auth-js >= 2.71 requirement explicit (lockfile already at 2.56.0).Step 2 — Replace 12s watchdog with instant reload on hung-fetch
WebKit silently aborts in-flight
fetch()calls when a tab enters bfcache (webkit.org/b/282506). If the user backgrounds the app DURING the initialgetSession(), the Promise never resolves andAuthStore.isLoading()staystrueforever.Previous code queued the resume reason and waited 12 seconds before reloading. That wait was theater — the Promise was already dead at bfcache enter, no amount of patience would unblock it. Detect
isLoading=trueat pageshow and reload immediately. Cooldown (60s sessionStorage) still protects against reload loops.Why now
pageshow.persisted, notvisibilitychange(Flarum#4588) — so we still need our own bfcache surface.Diff
~225 net lines removed across 2 commits:
d560bfba7refactor(webapp): replace 12s resume watchdog with instant reload on hung-fetch7d385f7e1refactor(webapp): delegate visibilitychange to Supabase auth-js + collapse pending stateFiles touched:
frontend/projects/webapp/src/app/core/lifecycle/resume-refresh.service.tsfrontend/projects/webapp/src/app/core/lifecycle/resume-refresh.service.spec.tsfrontend/package.jsonpnpm-lock.yamlBehavior changes
isLoading=true/welcome(unauthenticated route)Safety nets surviving
pageshow.persistedlistener (bfcache) — Pulpe-owned.document.wasDiscarded(low-memory) — Pulpe-owned.forceReloadOnSplashTimeout().Test plan
pnpm quality(typecheck + lint + format) — cleanpnpm test— 1874/1874 green (the 12s timer test was removed; 2 new instant-reload tests added)isLoading=trueat pageshow