@eintrek/erp-shell 0.1.12 → 0.1.13

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.
@@ -1,7 +1,13 @@
1
1
  /**
2
- * Invalidate ALL React Query queries when `organizationId` changes
3
- * (skips the initial mount). Use inside the ERP provider so org-scoped
4
- * data is refetched cleanly when the user switches org.
2
+ * Invalidate ALL React Query queries when `organizationId` changes between
3
+ * two real orgs (e.g. the user switches org in the picker). Skips the
4
+ * initial mount and the first-resolve transition (undefined/null/"" x)
5
+ * — that's the URL `[code]` segment finally syncing into the ERP context,
6
+ * not a real switch, and invalidating there triggers a cascade of refetches
7
+ * on top of the queries that already just fired.
8
+ *
9
+ * Use inside the ERP provider so org-scoped data is wiped cleanly when the
10
+ * user really does switch between two orgs.
5
11
  */
6
12
  export declare function useInvalidateQueriesOnOrgChange(organizationId: number | string | null | undefined): void;
7
13
  /**
package/dist/index.esm.js CHANGED
@@ -332,9 +332,15 @@ function useOrganizationIdState(initialOrganizationId, actions) {
332
332
  }
333
333
 
334
334
  /**
335
- * Invalidate ALL React Query queries when `organizationId` changes
336
- * (skips the initial mount). Use inside the ERP provider so org-scoped
337
- * data is refetched cleanly when the user switches org.
335
+ * Invalidate ALL React Query queries when `organizationId` changes between
336
+ * two real orgs (e.g. the user switches org in the picker). Skips the
337
+ * initial mount and the first-resolve transition (undefined/null/"" x)
338
+ * — that's the URL `[code]` segment finally syncing into the ERP context,
339
+ * not a real switch, and invalidating there triggers a cascade of refetches
340
+ * on top of the queries that already just fired.
341
+ *
342
+ * Use inside the ERP provider so org-scoped data is wiped cleanly when the
343
+ * user really does switch between two orgs.
338
344
  */
339
345
  function useInvalidateQueriesOnOrgChange(organizationId) {
340
346
  const queryClient = useQueryClient();
@@ -348,7 +354,15 @@ function useInvalidateQueriesOnOrgChange(organizationId) {
348
354
  }
349
355
  if (previousRef.current === organizationId)
350
356
  return;
357
+ const wasEmpty = previousRef.current === undefined ||
358
+ previousRef.current === null ||
359
+ previousRef.current === "";
351
360
  previousRef.current = organizationId;
361
+ // First-resolve: nothing to invalidate yet (queries either haven't run
362
+ // or are running with the right key already). Real org switches (a → b)
363
+ // still hit the invalidate path below.
364
+ if (wasEmpty)
365
+ return;
352
366
  queryClient.invalidateQueries();
353
367
  }, [organizationId, queryClient]);
354
368
  }