From 89119191b1ea8701361986b8675339cab75659ed Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Mon, 9 Mar 2026 14:49:06 -0400 Subject: [PATCH] fix(idaa): fix iframe scroll and parent URL not updating on navigation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs fixed: 1. scroll_to handler scrolled to page top (0,0) instead of the iframe's position in the Novi page. The iframe sits below Novi's own header/nav, so the user ended up looking at the Novi header instead of the iframe content after navigation. Fixed to use getBoundingClientRect() to scroll to 20px above the iframe's actual document position. Also added the missing scroll_to handler to idaa_novi_iframe_archives.html (it had none). 2. Parent URL not updating with event_id/post_id/archive_id on navigation. Detail pages sent postMessage using $idaa_slct. (the store), which is still null at synchronous init time — the $effect that populates it runs later. Fixed to read from data[data.account_id].slct. directly (set by the +page.ts load function from URL params before render). Also added afterNavigate to idaa/+layout.svelte to send scroll_to on all client-side navigations, covering cases the per-page blocks miss (e.g. navigating back to the list view). Co-Authored-By: Claude Sonnet 4.6 --- .../idaa/(idaa)/archives/[archive_id]/+page.svelte | 5 ++++- src/routes/idaa/(idaa)/bb/[post_id]/+page.svelte | 5 ++++- .../(idaa)/recovery_meetings/[event_id]/+page.svelte | 8 ++++++-- src/routes/idaa/+layout.svelte | 12 ++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/routes/idaa/(idaa)/archives/[archive_id]/+page.svelte b/src/routes/idaa/(idaa)/archives/[archive_id]/+page.svelte index 2fdc1b40..d77d10c6 100644 --- a/src/routes/idaa/(idaa)/archives/[archive_id]/+page.svelte +++ b/src/routes/idaa/(idaa)/archives/[archive_id]/+page.svelte @@ -285,7 +285,10 @@ if (browser) { console.log('Browser environment detected.'); - let message = { archive_id: $idaa_slct?.archive_id ?? null }; + // NOTE: Use data[data.account_id].slct.archive_id (from load / URL params), + // NOT $idaa_slct.archive_id (the store). The store is updated by a $effect that runs + // after this synchronous block — reading it here sends the old/null value. + let message = { archive_id: data[data.account_id]?.slct?.archive_id ?? null }; window.parent.postMessage(message, '*'); if ($ae_loc?.iframe) { diff --git a/src/routes/idaa/(idaa)/bb/[post_id]/+page.svelte b/src/routes/idaa/(idaa)/bb/[post_id]/+page.svelte index f3eaae1f..b38b70b3 100644 --- a/src/routes/idaa/(idaa)/bb/[post_id]/+page.svelte +++ b/src/routes/idaa/(idaa)/bb/[post_id]/+page.svelte @@ -94,7 +94,10 @@ if (browser) { console.log('Browser environment detected.'); - let message = { post_id: $idaa_slct?.post_id ?? null }; + // NOTE: Use data[data.account_id].slct.post_id (from load / URL params), + // NOT $idaa_slct.post_id (the store). The store is updated by a $effect that runs + // after this synchronous block — reading it here sends the old/null value. + let message = { post_id: data[data.account_id]?.slct?.post_id ?? null }; window.parent.postMessage(message, '*'); if ($ae_loc?.iframe) { diff --git a/src/routes/idaa/(idaa)/recovery_meetings/[event_id]/+page.svelte b/src/routes/idaa/(idaa)/recovery_meetings/[event_id]/+page.svelte index 08cd604e..6174ac67 100644 --- a/src/routes/idaa/(idaa)/recovery_meetings/[event_id]/+page.svelte +++ b/src/routes/idaa/(idaa)/recovery_meetings/[event_id]/+page.svelte @@ -37,7 +37,7 @@ idaa_prom } from '$lib/stores/ae_idaa_stores'; - import Event_obj_id_edit from '.././ae_idaa_comp__event_obj_id_edit.svelte'; + import Event_obj_id_edit from '.././ae_idaa_comp__event_obj_id_edit_v2.svelte'; import Event_obj_id_view from '.././ae_idaa_comp__event_obj_id_view.svelte'; import Help_tech from '$lib/app_components/e_app_help_tech.svelte'; @@ -94,7 +94,11 @@ if (browser) { console.log('Browser environment detected.'); - let message = { event_id: $idaa_slct?.event_id ?? null }; + // NOTE: Use data[data.account_id].slct.event_id (from the load function / URL params), + // NOT $idaa_slct.event_id (the store). The store is updated by a $effect that runs + // after this synchronous block — reading it here would send the old/null value and + // fail to update the parent page URL. + let message = { event_id: data[data.account_id]?.slct?.event_id ?? null }; window.parent.postMessage(message, '*'); if ($ae_loc?.iframe) { diff --git a/src/routes/idaa/+layout.svelte b/src/routes/idaa/+layout.svelte index eb976bd6..05286c7a 100644 --- a/src/routes/idaa/+layout.svelte +++ b/src/routes/idaa/+layout.svelte @@ -3,6 +3,7 @@ // *** Import Svelte specific import { browser } from '$app/environment'; + import { afterNavigate } from '$app/navigation'; // *** Import other supporting libraries // import * as icons from '@lucide/svelte'; @@ -165,6 +166,17 @@ // }); }); + // NOTE: Fires after every client-side navigation within the IDAA module. + // Scrolls the parent Novi page to show the top of the iframe so the user + // doesn't land in the middle of new content after clicking a post/meeting/archive. + // The individual detail pages also send scroll_to on load — this catches the + // cases they miss (e.g. navigating back to the list view). + afterNavigate(() => { + if ($ae_loc?.iframe) { + window.parent.postMessage({ scroll_to: 0 }, '*'); + } + }); + let iframe = $derived(data.url.searchParams.get('iframe')); $effect(() => {