@the-portland-company/shell 0.76.0 → 0.76.1

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,11 @@
1
+ ## 0.76.1
2
+
3
+ One chrome read per endpoint per page load. `me`, `notifications` and `communications/fuel-status` each fired twice (Surveys F4 measurement).
4
+
5
+ - `useChromeMode` reuses the provider's boot `me` when its `account` is the active org, else reads through the de-duped cache. New `useNavChromeDedupedFetch`.
6
+ - `FuelAction` / `NotificationsAction` do not read without an org, and `ChromeTopBarActions` passes the org only after the org list settles.
7
+ - Test: `__tests__/chromeFetchDedupe.test.tsx`.
8
+
1
9
  ## 0.76.0
2
10
 
3
11
  Auth-owned active org, shell phase (Global-Rules v38, UI-Platform v46; plan `specs/docs/auth-owned-active-org-plan.md` §3.2). Opt-in: no change for apps that do not pass `tokenOrg`.
@@ -538,6 +538,9 @@ function useChromeMe() {
538
538
  const ctx = react.useContext(NavChromeContext);
539
539
  return { me: ctx?.me ?? null, loaded: ctx?.meLoaded ?? false };
540
540
  }
541
+ function useNavChromeDedupedFetch() {
542
+ return react.useContext(NavChromeContext)?.dedupedFetch ?? null;
543
+ }
541
544
  function useNavChromeFetcher() {
542
545
  return react.useContext(NavChromeContext)?.fetchJson ?? null;
543
546
  }
@@ -865,6 +868,10 @@ function FuelAction({ orgId }) {
865
868
  const [error, setError] = react.useState(false);
866
869
  react.useEffect(() => {
867
870
  let cancelled = false;
871
+ if (!orgId) {
872
+ setLoading(false);
873
+ return;
874
+ }
868
875
  setLoading(true);
869
876
  setError(false);
870
877
  setFuel(null);
@@ -1100,6 +1107,10 @@ function NotificationsAction({ orgId }) {
1100
1107
  }, [orgId]);
1101
1108
  react.useEffect(() => {
1102
1109
  let cancelled = false;
1110
+ if (!orgId) {
1111
+ setLoading(false);
1112
+ return;
1113
+ }
1103
1114
  setLoading(true);
1104
1115
  setError(false);
1105
1116
  setPayload(null);
@@ -5339,6 +5350,7 @@ function PolitogyAppChrome({
5339
5350
  function ChromeTopBarActions() {
5340
5351
  const state = useChromeState();
5341
5352
  if (!state) return null;
5353
+ const settledOrgId = state.orgsLoading ? null : state.orgId;
5342
5354
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5343
5355
  /* @__PURE__ */ jsxRuntime.jsx(
5344
5356
  TopBarWidgetSlot,
@@ -5348,9 +5360,9 @@ function ChromeTopBarActions() {
5348
5360
  children: /* @__PURE__ */ jsxRuntime.jsx(ChromeDevNotesMenu, {})
5349
5361
  }
5350
5362
  ),
5351
- /* @__PURE__ */ jsxRuntime.jsx(FuelAction, { orgId: state.orgId }),
5363
+ /* @__PURE__ */ jsxRuntime.jsx(FuelAction, { orgId: settledOrgId }),
5352
5364
  /* @__PURE__ */ jsxRuntime.jsx(SpecOverlayAction, { orgId: state.orgId, orgName: state.orgs.find((o) => o.id === state.orgId)?.name ?? null }),
5353
- /* @__PURE__ */ jsxRuntime.jsx(NotificationsAction, { orgId: state.orgId }),
5365
+ /* @__PURE__ */ jsxRuntime.jsx(NotificationsAction, { orgId: settledOrgId }),
5354
5366
  /* @__PURE__ */ jsxRuntime.jsx(SupportAction, { orgId: state.orgId, orgs: state.orgs.length ? state.orgs : void 0 })
5355
5367
  ] });
5356
5368
  }
@@ -5437,7 +5449,8 @@ var MODE_DEFS = [
5437
5449
  function useChromeMode(arg = {}) {
5438
5450
  const { fallbackModeId = "relationship", pinnedModeId } = typeof arg === "string" ? { fallbackModeId: arg, pinnedModeId: void 0 } : arg;
5439
5451
  const ctx = react.useContext(ChromeStateContext);
5440
- const nav = useNavChromeFetcher();
5452
+ const dedupedFetch = useNavChromeDedupedFetch();
5453
+ const { me, loaded: meLoaded } = useChromeMe();
5441
5454
  const orgId = ctx?.orgId ?? null;
5442
5455
  const [entitled, setEntitled] = react.useState(null);
5443
5456
  const [selectedModeId, setSelectedModeId] = react.useState(null);
@@ -5449,9 +5462,14 @@ function useChromeMode(arg = {}) {
5449
5462
  }
5450
5463
  }, []);
5451
5464
  react.useEffect(() => {
5452
- if (!nav || !orgId) return;
5465
+ if (!dedupedFetch || !orgId || !meLoaded) return;
5466
+ const bootMe = me;
5467
+ if (bootMe && bootMe.account === orgId && bootMe.modes !== void 0) {
5468
+ setEntitled(bootMe.modes ?? null);
5469
+ return;
5470
+ }
5453
5471
  let cancelled = false;
5454
- nav("me", { headers: { "x-contacts-org": orgId } }).then((data) => {
5472
+ dedupedFetch("me", { headers: { "x-contacts-org": orgId } }, { orgId }).then((data) => {
5455
5473
  if (cancelled) return;
5456
5474
  const modes = data?.modes ?? null;
5457
5475
  setEntitled(modes);
@@ -5460,7 +5478,7 @@ function useChromeMode(arg = {}) {
5460
5478
  return () => {
5461
5479
  cancelled = true;
5462
5480
  };
5463
- }, [nav, orgId]);
5481
+ }, [dedupedFetch, me, meLoaded, orgId]);
5464
5482
  const options = MODE_DEFS.filter((m) => entitled?.[m.id]);
5465
5483
  const pinned = pinnedModeId ? MODE_DEFS.find((m) => m.id === pinnedModeId) ?? null : null;
5466
5484
  const selected = selectedModeId ? options.find((m) => m.id === selectedModeId) ?? null : null;