@the-portland-company/shell 0.99.1 → 0.101.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## 0.101.0
2
+
3
+ A new photo or name saved on My Profile shows in the left-bar user card at once (bug seen live 2026-11-14, Ben: "updating profile picture from My Profile does not immediately display in the personal information footer").
4
+
5
+ - **Cause.** `NavChromeProvider` read `me` (the user's name and photo) once per page and kept it. My Profile saved the new photo and updated its own preview, but nothing told the chrome, so the card kept the old photo until a reload.
6
+ - **Fix.** The provider now reads `me` again when the page fires the `politogy:profile-changed` window event, skipping the read cache. Only the newest read lands, and a failed re-read keeps the last good identity.
7
+ - New exports on `./native`: `announceProfileChanged()` (fires the event) and `PROFILE_CHANGED_EVENT`.
8
+ - Tests: `__tests__/profileChanged.test.tsx` (new).
9
+
10
+ ## 0.100.0
11
+
12
+ New pages open at the top (Ben 2026-11-08, clicked "Save as written" and "Go, all Modes" in the scroll-to-top session box; Reference/UI-Platform → URL state → "Scroll position"). Ben: "when clicking from one tab to another … the next page starts out slightly scrolled down. I need every new page to start fully scrolled at the top."
13
+
14
+ - **Cause.** Next's App Router only scrolls when the new page's top edge is off screen, so a page scrolled down a little kept that offset. And most pages and tabs switch by query parameter (`?page=…&tab=…`) on the same path, which nothing reset.
15
+ - **Fix.** `NavAppShell` (so every app on `PolitogyAppFrame`) now scrolls the window to the top, instantly, when the URL moves to a new page: a different path, or a different `mode`, `page` or `tab`. Changing only `section`, `org_id` or a feature parameter (filters, pagination) keeps the place; filling a missing default is not a new page; Back / Forward keep the browser's own position; a `#anchor` URL lands on its anchor. Uses the Navigation API where present, with a `popstate` + render-time check as the fallback, and survives apps that remount their chrome on each page (Tribes, Surveys).
16
+ - New exports on `./native`: `useScrollToTopOnNewPage`, `isNewPage`, `pageIdentityOf`, type `PageIdentity`.
17
+ - Tests: `__tests__/scrollToTop.test.tsx` (new).
18
+
1
19
  ## 0.99.1
2
20
 
3
21
  The user card says "Account Manager" for an Account Manager (bug seen live 2026-11-07: benedtl@hotmail.com, `account_manager` in "TEST Campaign A (link test)", a Linked Accounts roster membership, was shown as "Member").
@@ -422,6 +422,75 @@ function SpeculationRulesScript({ items }) {
422
422
  }, [items, origin]);
423
423
  return null;
424
424
  }
425
+ var PAGE_KEYS = ["mode", "page", "tab"];
426
+ function pageIdentityOf(pathname, search) {
427
+ const params = new URLSearchParams(search.startsWith("?") ? search.slice(1) : search);
428
+ const path = pathname.length > 1 ? pathname.replace(/\/+$/, "") : pathname;
429
+ return {
430
+ pathname: path || "/",
431
+ mode: params.get("mode") || null,
432
+ page: params.get("page") || null,
433
+ tab: params.get("tab") || null
434
+ };
435
+ }
436
+ function isNewPage(prev, next) {
437
+ if (prev.pathname !== next.pathname) return true;
438
+ return PAGE_KEYS.some((k) => prev[k] !== null && next[k] !== prev[k]);
439
+ }
440
+ function scrollWindowToTop() {
441
+ if (window.scrollX === 0 && window.scrollY === 0) return;
442
+ try {
443
+ window.scrollTo({ top: 0, left: 0, behavior: "instant" });
444
+ } catch {
445
+ window.scrollTo(0, 0);
446
+ }
447
+ }
448
+ var lastIdentity = null;
449
+ var listeners = 0;
450
+ var detach = null;
451
+ function currentIdentity() {
452
+ return pageIdentityOf(window.location.pathname, window.location.search);
453
+ }
454
+ function check(traverse = false) {
455
+ const next = currentIdentity();
456
+ const prev = lastIdentity;
457
+ lastIdentity = next;
458
+ if (!prev || traverse) return;
459
+ if (!isNewPage(prev, next)) return;
460
+ if (window.location.hash) return;
461
+ scrollWindowToTop();
462
+ }
463
+ function attach() {
464
+ const nav = window.navigation;
465
+ if (nav && typeof nav.addEventListener === "function") {
466
+ const onEntryChange = (e) => {
467
+ check(e.navigationType === "traverse");
468
+ };
469
+ nav.addEventListener("currententrychange", onEntryChange);
470
+ return () => nav.removeEventListener("currententrychange", onEntryChange);
471
+ }
472
+ const onPopState = () => check(true);
473
+ window.addEventListener("popstate", onPopState);
474
+ return () => window.removeEventListener("popstate", onPopState);
475
+ }
476
+ var useIsoLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
477
+ function useScrollToTopOnNewPage() {
478
+ react.useEffect(() => {
479
+ if (listeners === 0) detach = attach();
480
+ listeners += 1;
481
+ return () => {
482
+ listeners -= 1;
483
+ if (listeners === 0) {
484
+ detach?.();
485
+ detach = null;
486
+ }
487
+ };
488
+ }, []);
489
+ useIsoLayoutEffect(() => {
490
+ if (lastIdentity) check();
491
+ else lastIdentity = currentIdentity();
492
+ });
493
+ }
425
494
 
426
495
  // src/native/credits.ts
427
496
  var CREDIT_TYPE_ORDER = [
@@ -740,16 +809,27 @@ function NavChromeProvider({
740
809
  const [meLoaded, setMeLoaded] = react.useState(false);
741
810
  react.useEffect(() => {
742
811
  let cancelled = false;
743
- dedupedFetch("me", void 0).then((data) => {
744
- if (!cancelled) setMe(data);
745
- }).catch(() => {
746
- }).finally(() => {
747
- if (!cancelled) setMeLoaded(true);
748
- });
812
+ let latest = 0;
813
+ const load = () => {
814
+ const call = ++latest;
815
+ dedupedFetch("me", void 0).then((data) => {
816
+ if (!cancelled && call === latest) setMe(data);
817
+ }).catch(() => {
818
+ }).finally(() => {
819
+ if (!cancelled) setMeLoaded(true);
820
+ });
821
+ };
822
+ load();
823
+ const onProfileChanged = () => {
824
+ invalidateChromeCache("me");
825
+ load();
826
+ };
827
+ window.addEventListener(PROFILE_CHANGED_EVENT, onProfileChanged);
749
828
  return () => {
750
829
  cancelled = true;
830
+ window.removeEventListener(PROFILE_CHANGED_EVENT, onProfileChanged);
751
831
  };
752
- }, [dedupedFetch]);
832
+ }, [dedupedFetch, invalidateChromeCache]);
753
833
  return /* @__PURE__ */ jsxRuntime.jsx(
754
834
  NavChromeContext.Provider,
755
835
  {
@@ -758,6 +838,7 @@ function NavChromeProvider({
758
838
  }
759
839
  );
760
840
  }
841
+ var PROFILE_CHANGED_EVENT = "politogy:profile-changed";
761
842
  function useChromeMe() {
762
843
  const ctx = react.useContext(NavChromeContext);
763
844
  return { me: ctx?.me ?? null, loaded: ctx?.meLoaded ?? false };
@@ -3463,6 +3544,7 @@ function NavAppShell({
3463
3544
  children
3464
3545
  }) {
3465
3546
  useCloseNavDetailsOnOutsideClick();
3547
+ useScrollToTopOnNewPage();
3466
3548
  if (contentWrapper === "bare") {
3467
3549
  warnDeprecated(
3468
3550
  "contentWrapper",
@@ -3673,7 +3755,7 @@ function watchLogout(onLogout, options = {}) {
3673
3755
  cleanup();
3674
3756
  onLogout();
3675
3757
  };
3676
- const check = () => {
3758
+ const check2 = () => {
3677
3759
  const at = readLogoutCookie();
3678
3760
  if (at !== null) fire(at);
3679
3761
  };
@@ -3687,15 +3769,15 @@ function watchLogout(onLogout, options = {}) {
3687
3769
  } catch {
3688
3770
  channel = null;
3689
3771
  }
3690
- const timer = window.setInterval(check, intervalMs);
3691
- window.addEventListener("visibilitychange", check);
3692
- window.addEventListener("focus", check);
3693
- window.addEventListener("pageshow", check);
3772
+ const timer = window.setInterval(check2, intervalMs);
3773
+ window.addEventListener("visibilitychange", check2);
3774
+ window.addEventListener("focus", check2);
3775
+ window.addEventListener("pageshow", check2);
3694
3776
  function cleanup() {
3695
3777
  window.clearInterval(timer);
3696
- window.removeEventListener("visibilitychange", check);
3697
- window.removeEventListener("focus", check);
3698
- window.removeEventListener("pageshow", check);
3778
+ window.removeEventListener("visibilitychange", check2);
3779
+ window.removeEventListener("focus", check2);
3780
+ window.removeEventListener("pageshow", check2);
3699
3781
  try {
3700
3782
  channel?.close();
3701
3783
  } catch {