From a713e0312dc725720f3403d1fb42ecc0c1bcbbfe Mon Sep 17 00:00:00 2001 From: dev Date: Tue, 5 May 2026 21:12:51 +0200 Subject: [PATCH] =?UTF-8?q?Nexo=20P1=20fix=20=E2=80=94=20stop=20the=20load?= =?UTF-8?q?-on-session=20effects=20from=20looping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every product page (discover, matches, chat, profile, photos) had the same pattern: an `$effect` reads `nexo.session()`, then calls a `load()` / `hydrate()` helper. Inside that helper Svelte's reactivity tracks the `loading` / `profile` / etc. cells the helper writes to, so when the helper finishes (sets `loading = false`) the effect sees its own write and re-runs — and triggers the same fetch all over again. Result: the dev server console fills with continuous `/api/discover`, `/api/matches`, `/api/profile/me` requests as long as the page is mounted. Fix per page: - **Discover, Matches**: introduce an `initialised` guard plus `untrack(() => void load(...))`. The first session-ready transition triggers the fetch; the helper's writes no longer feed back into the effect. - **Chat**: the trigger key is the URL `matchId` (it can change while the page is mounted via in-app navigation). A `loadedFor` cell holds the last id we fetched so a session-cell write doesn't re-fetch the same thread, and the actual `load()` call is wrapped in `untrack`. - **Profile**: `hydrate()` populates eight reactive cells. Without `untrack` the effect kept hydrating the form on every keystroke, clobbering the user's edits. Now hydrated only when the profile id changes. - **Photos**: shallow-compare profile by `id + updated` before re-assigning so identity-stable refreshes don't poke `$state` proxies that downstream code reads. The redirect branches (anonymous → /login, no-profile → /onboarding) keep working because `goto` unmounts the current page, so the mid-render effect simply stops running. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/web/routes/dating/chat/[matchId]/+page.svelte | 12 ++++++++++-- src/web/routes/dating/discover/+page.svelte | 11 ++++++++++- src/web/routes/dating/matches/+page.svelte | 9 ++++++++- src/web/routes/dating/profile/+page.svelte | 11 ++++++++++- src/web/routes/dating/profile/photos/+page.svelte | 8 +++++++- 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/web/routes/dating/chat/[matchId]/+page.svelte b/src/web/routes/dating/chat/[matchId]/+page.svelte index fb84e9a..3daa545 100644 --- a/src/web/routes/dating/chat/[matchId]/+page.svelte +++ b/src/web/routes/dating/chat/[matchId]/+page.svelte @@ -1,7 +1,7 @@