@eintrek/erp-shell 0.1.36 → 0.1.38

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/dist/index.esm.js CHANGED
@@ -363,7 +363,22 @@ function useInvalidateQueriesOnOrgChange(organizationId) {
363
363
  // still hit the invalidate path below.
364
364
  if (wasEmpty)
365
365
  return;
366
- queryClient.invalidateQueries();
366
+ // Remove, not invalidate.
367
+ //
368
+ // invalidateQueries marks entries stale and refetches the mounted ones,
369
+ // which leaves the previous organisation's rows sitting in the cache and
370
+ // on screen until a refetch lands. Any query whose key does not carry the
371
+ // organisation — and the request is scoped by the X-Organization-ID
372
+ // header, so most keys have no reason to — then reads as a cache hit for
373
+ // the new organisation and renders the old one's data under the new
374
+ // one's name. A colleague found /O26000021/employee showing three
375
+ // employees belonging to O26000033, with the breadcrumb and the title
376
+ // both correct.
377
+ //
378
+ // Dropping the entries costs a loading state after every switch, which is
379
+ // the honest thing to show: nothing fetched under one tenant is worth
380
+ // keeping once the tenant changes.
381
+ queryClient.removeQueries();
367
382
  }, [organizationId, queryClient]);
368
383
  }
369
384
  /**
@@ -1874,7 +1889,19 @@ instance.interceptors.request.use(async (config) => {
1874
1889
  if (token) {
1875
1890
  config.headers.Authorization = `Bearer ${token}`;
1876
1891
  }
1877
- const organizationId = getOrgFromCookie() || getOrganizationId();
1892
+ // localStorage first, cookie second.
1893
+ //
1894
+ // Both are written by the same state machine, but not at the same moment:
1895
+ // setOrganizationId writes localStorage synchronously and then awaits a
1896
+ // server action for the cookie. Preferring the cookie meant every request
1897
+ // fired during that round trip carried the previous organisation — while
1898
+ // the query params, built from React state, already carried the new one.
1899
+ //
1900
+ // The backend scopes by this header and ignores organization_id in the
1901
+ // query, so those requests asked for organisation A and were handed B, and
1902
+ // the answer landed in the cache under A's key. No amount of cache clearing
1903
+ // reaches that: the entry is wrong, not stale.
1904
+ const organizationId = getOrganizationId() || getOrgFromCookie();
1878
1905
  if (organizationId) {
1879
1906
  config.headers["X-Organization-ID"] = organizationId;
1880
1907
  }