@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.js CHANGED
@@ -382,7 +382,22 @@ function useInvalidateQueriesOnOrgChange(organizationId) {
382
382
  // still hit the invalidate path below.
383
383
  if (wasEmpty)
384
384
  return;
385
- queryClient.invalidateQueries();
385
+ // Remove, not invalidate.
386
+ //
387
+ // invalidateQueries marks entries stale and refetches the mounted ones,
388
+ // which leaves the previous organisation's rows sitting in the cache and
389
+ // on screen until a refetch lands. Any query whose key does not carry the
390
+ // organisation — and the request is scoped by the X-Organization-ID
391
+ // header, so most keys have no reason to — then reads as a cache hit for
392
+ // the new organisation and renders the old one's data under the new
393
+ // one's name. A colleague found /O26000021/employee showing three
394
+ // employees belonging to O26000033, with the breadcrumb and the title
395
+ // both correct.
396
+ //
397
+ // Dropping the entries costs a loading state after every switch, which is
398
+ // the honest thing to show: nothing fetched under one tenant is worth
399
+ // keeping once the tenant changes.
400
+ queryClient.removeQueries();
386
401
  }, [organizationId, queryClient]);
387
402
  }
388
403
  /**
@@ -1893,7 +1908,19 @@ instance.interceptors.request.use(async (config) => {
1893
1908
  if (token) {
1894
1909
  config.headers.Authorization = `Bearer ${token}`;
1895
1910
  }
1896
- const organizationId = getOrgFromCookie() || getOrganizationId();
1911
+ // localStorage first, cookie second.
1912
+ //
1913
+ // Both are written by the same state machine, but not at the same moment:
1914
+ // setOrganizationId writes localStorage synchronously and then awaits a
1915
+ // server action for the cookie. Preferring the cookie meant every request
1916
+ // fired during that round trip carried the previous organisation — while
1917
+ // the query params, built from React state, already carried the new one.
1918
+ //
1919
+ // The backend scopes by this header and ignores organization_id in the
1920
+ // query, so those requests asked for organisation A and were handed B, and
1921
+ // the answer landed in the cache under A's key. No amount of cache clearing
1922
+ // reaches that: the entry is wrong, not stale.
1923
+ const organizationId = getOrganizationId() || getOrgFromCookie();
1897
1924
  if (organizationId) {
1898
1925
  config.headers["X-Organization-ID"] = organizationId;
1899
1926
  }