fix(idaa): fix iframe scroll and parent URL not updating on navigation

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.<id> (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.<id> 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 <noreply@anthropic.com>
This commit is contained in:
Scott Idem
2026-03-09 14:49:06 -04:00
parent eb0dcb17f8
commit 89119191b1
4 changed files with 26 additions and 4 deletions

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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(() => {