@gears-frontx/react 0.2.0-alpha.0 → 0.2.0-alpha.2

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.cjs CHANGED
@@ -222,7 +222,7 @@ __export(src_exports, {
222
222
  module.exports = __toCommonJS(src_exports);
223
223
 
224
224
  // src/FrontXProvider.tsx
225
- var import_react4 = require("react");
225
+ var import_react5 = require("react");
226
226
  var import_react_redux = require("react-redux");
227
227
  var import_framework3 = require("@gears-frontx/framework");
228
228
 
@@ -259,7 +259,7 @@ var MfeProvider = ({ value, children }) => {
259
259
  };
260
260
 
261
261
  // src/queryClient.tsx
262
- var import_react3 = __toESM(require("react"), 1);
262
+ var import_react4 = __toESM(require("react"), 1);
263
263
  var import_react_query = require("@tanstack/react-query");
264
264
  var import_framework2 = require("@gears-frontx/framework");
265
265
 
@@ -368,13 +368,23 @@ function createQueryCache(queryClient) {
368
368
  };
369
369
  }
370
370
 
371
+ // src/hooks/useLatest.ts
372
+ var import_react3 = require("react");
373
+ function useLatest(value) {
374
+ const ref = (0, import_react3.useRef)(value);
375
+ (0, import_react3.useEffect)(() => {
376
+ ref.current = value;
377
+ });
378
+ return ref;
379
+ }
380
+
371
381
  // src/queryClient.tsx
372
382
  var import_jsx_runtime2 = require("react/jsx-runtime");
373
383
  var APP_QUERY_CLIENT_SYMBOL = /* @__PURE__ */ Symbol.for("frontx:query-cache:app-client");
374
384
  var APP_QUERY_CLIENT_RESOLVER_SYMBOL = /* @__PURE__ */ Symbol.for("frontx:query-cache:app-client-resolver");
375
385
  var APP_QUERY_CLIENT_ACTIVATOR_SYMBOL = /* @__PURE__ */ Symbol.for("frontx:query-cache:app-client-activator");
376
- var FrontXQueryClientContext = (0, import_react3.createContext)(void 0);
377
- var useCommitEffect = typeof globalThis.window === "undefined" ? import_react3.useEffect : import_react3.useLayoutEffect;
386
+ var FrontXQueryClientContext = (0, import_react4.createContext)(void 0);
387
+ var useCommitEffect = typeof globalThis.window === "undefined" ? import_react4.useEffect : import_react4.useLayoutEffect;
378
388
  function resolveFrontXQueryClient(app) {
379
389
  const clientApp = app;
380
390
  return clientApp[APP_QUERY_CLIENT_SYMBOL] ?? clientApp[APP_QUERY_CLIENT_RESOLVER_SYMBOL]?.();
@@ -399,8 +409,8 @@ function bootstrapFrontXQueryClient(app) {
399
409
  return resolveFrontXQueryClient(app);
400
410
  }
401
411
  function useBootstrappedFrontXQueryClient(app) {
402
- const fromApp = (0, import_react3.useMemo)(() => bootstrapFrontXQueryClient(app), [app]);
403
- const [eventResolvedClient, setEventResolvedClient] = (0, import_react3.useState)(
412
+ const fromApp = (0, import_react4.useMemo)(() => bootstrapFrontXQueryClient(app), [app]);
413
+ const [eventResolvedClient, setEventResolvedClient] = (0, import_react4.useState)(
404
414
  void 0
405
415
  );
406
416
  const queryClient = fromApp ?? (eventResolvedClient?.app === app ? eventResolvedClient.queryClient : void 0);
@@ -442,7 +452,7 @@ function FrontXQueryClientProvider({
442
452
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FrontXQueryClientContext.Provider, { value: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_query.QueryClientProvider, { client: queryClient, children }) });
443
453
  }
444
454
  function useOptionalFrontXQueryClient() {
445
- return (0, import_react3.useContext)(FrontXQueryClientContext);
455
+ return (0, import_react4.useContext)(FrontXQueryClientContext);
446
456
  }
447
457
  function useRequiredFrontXQueryClient() {
448
458
  const queryClient = useOptionalFrontXQueryClient();
@@ -613,21 +623,22 @@ function useFrontXSuspenseInfiniteQuery(options) {
613
623
  }
614
624
  function useFrontXMutation(options, callbackCtx) {
615
625
  useRequiredFrontXQueryClient();
616
- const latestRef = import_react3.default.useRef({ options, callbackCtx });
617
- latestRef.current = { options, callbackCtx };
618
- const fetchAbortControllersRef = import_react3.default.useRef(/* @__PURE__ */ new Set());
619
- import_react3.default.useEffect(() => {
620
- const fetchAbortControllers = fetchAbortControllersRef.current;
621
- return () => {
622
- if (latestRef.current.options.abortOnUnmount) {
623
- for (const controller of fetchAbortControllers) {
624
- controller.abort();
625
- }
626
- fetchAbortControllers.clear();
626
+ const latestRef = useLatest({ options, callbackCtx });
627
+ const fetchAbortControllersRef = import_react4.default.useRef(/* @__PURE__ */ new Set());
628
+ const abortFetchesOnUnmount = import_react4.default.useEffectEvent(() => {
629
+ if (options.abortOnUnmount) {
630
+ for (const controller of fetchAbortControllersRef.current) {
631
+ controller.abort();
627
632
  }
633
+ fetchAbortControllersRef.current.clear();
634
+ }
635
+ });
636
+ import_react4.default.useEffect(() => {
637
+ return () => {
638
+ abortFetchesOnUnmount();
628
639
  };
629
640
  }, []);
630
- const mutationFn = import_react3.default.useCallback((variables, context) => {
641
+ const mutationFn = import_react4.default.useCallback((variables, context) => {
631
642
  const cancelOnSupersede = latestRef.current.options.cancelOnSupersede;
632
643
  if (cancelOnSupersede) {
633
644
  for (const controller2 of fetchAbortControllersRef.current) {
@@ -648,23 +659,23 @@ function useFrontXMutation(options, callbackCtx) {
648
659
  return latestRef.current.options.endpoint.fetch(variables, { signal: controller.signal }).finally(() => {
649
660
  fetchAbortControllersRef.current.delete(controller);
650
661
  });
651
- }, []);
652
- const onMutate = import_react3.default.useCallback((variables, _context) => {
662
+ }, [latestRef]);
663
+ const onMutate = import_react4.default.useCallback((variables, _context) => {
653
664
  const current = latestRef.current;
654
665
  if (!current.options.onMutate) {
655
666
  return void 0;
656
667
  }
657
668
  return current.options.onMutate(variables, current.callbackCtx);
658
- }, []);
659
- const onSuccess = import_react3.default.useCallback((data, variables, context) => {
669
+ }, [latestRef]);
670
+ const onSuccess = import_react4.default.useCallback((data, variables, context) => {
660
671
  const current = latestRef.current;
661
672
  return current.options.onSuccess?.(data, variables, context, current.callbackCtx);
662
- }, []);
663
- const onError = import_react3.default.useCallback((error, variables, context) => {
673
+ }, [latestRef]);
674
+ const onError = import_react4.default.useCallback((error, variables, context) => {
664
675
  const current = latestRef.current;
665
676
  return current.options.onError?.(error, variables, context, current.callbackCtx);
666
- }, []);
667
- const onSettled = import_react3.default.useCallback((data, error, variables, context) => {
677
+ }, [latestRef]);
678
+ const onSettled = import_react4.default.useCallback((data, error, variables, context) => {
668
679
  const current = latestRef.current;
669
680
  return current.options.onSettled?.(
670
681
  data,
@@ -673,7 +684,7 @@ function useFrontXMutation(options, callbackCtx) {
673
684
  context,
674
685
  current.callbackCtx
675
686
  );
676
- }, []);
687
+ }, [latestRef]);
677
688
  const mutation = (0, import_react_query.useMutation)({
678
689
  mutationFn,
679
690
  onMutate: options.onMutate ? onMutate : void 0,
@@ -709,14 +720,14 @@ var FrontXProvider = ({
709
720
  app: providedApp,
710
721
  mfeBridge
711
722
  }) => {
712
- const [stableConfig, setStableConfig] = (0, import_react4.useState)(config);
723
+ const [stableConfig, setStableConfig] = (0, import_react5.useState)(config);
713
724
  if (!shallowEqual(
714
725
  stableConfig,
715
726
  config
716
727
  )) {
717
728
  setStableConfig(config);
718
729
  }
719
- const app = (0, import_react4.useMemo)(() => {
730
+ const app = (0, import_react5.useMemo)(() => {
720
731
  if (providedApp) {
721
732
  return providedApp;
722
733
  }
@@ -724,7 +735,7 @@ var FrontXProvider = ({
724
735
  }, [providedApp, stableConfig]);
725
736
  const queryClient = useBootstrappedFrontXQueryClient(app);
726
737
  const deferQuerySubtree = hasFrontXQueryClientActivator(app) && queryClient === void 0;
727
- (0, import_react4.useEffect)(() => {
738
+ (0, import_react5.useEffect)(() => {
728
739
  if (queryClient || hasFrontXQueryClientActivator(app) || process.env.NODE_ENV === "production" || process.env.NODE_ENV === "test" || process.env.VITEST === "true") {
729
740
  return;
730
741
  }
@@ -732,7 +743,7 @@ var FrontXProvider = ({
732
743
  "[FrontXProvider] No query cache available. Add queryCache() or queryCacheShared() to your plugin composition. useApiQuery/useApiMutation will fail without it."
733
744
  );
734
745
  }, [app, queryClient]);
735
- (0, import_react4.useEffect)(() => {
746
+ (0, import_react5.useEffect)(() => {
736
747
  return () => {
737
748
  if (!providedApp) {
738
749
  app.destroy();
@@ -747,7 +758,7 @@ var FrontXProvider = ({
747
758
  };
748
759
 
749
760
  // src/hooks/useCanAccess.ts
750
- var import_react5 = require("react");
761
+ var import_react6 = require("react");
751
762
  function serializeRecordValue(value) {
752
763
  if (value === null) return "n:";
753
764
  if (typeof value === "string") return `s:${value}`;
@@ -764,24 +775,23 @@ function accessQueryKey(query) {
764
775
  function getAuthRuntime(app) {
765
776
  return app.auth ?? null;
766
777
  }
778
+ var DENIED_NO_AUTH = { allow: false, isResolving: false };
767
779
  function useCanAccess(query) {
768
780
  const app = useFrontX();
781
+ const auth2 = getAuthRuntime(app);
769
782
  const stableKey = accessQueryKey(query);
770
- const [stableQuery, setStableQuery] = (0, import_react5.useState)(() => query);
771
- const [storedKey, setStoredKey] = (0, import_react5.useState)(stableKey);
772
- const [result, setResult] = (0, import_react5.useState)({ allow: false, isResolving: true });
773
- if (storedKey !== stableKey) {
774
- setStoredKey(stableKey);
783
+ const [stableQuery, setStableQuery] = (0, import_react6.useState)(() => query);
784
+ const [runState, setRunState] = (0, import_react6.useState)({ auth: auth2, stableKey });
785
+ const [result, setResult] = (0, import_react6.useState)({ allow: false, isResolving: true });
786
+ if (runState.auth !== auth2 || runState.stableKey !== stableKey) {
787
+ setRunState({ auth: auth2, stableKey });
775
788
  setStableQuery(query);
776
789
  setResult({ allow: false, isResolving: true });
777
790
  }
778
- (0, import_react5.useEffect)(() => {
779
- const auth2 = getAuthRuntime(app);
791
+ (0, import_react6.useEffect)(() => {
780
792
  if (!auth2) {
781
- setResult({ allow: false, isResolving: false });
782
793
  return;
783
794
  }
784
- setResult({ allow: false, isResolving: true });
785
795
  let alive = true;
786
796
  const controller = new AbortController();
787
797
  void auth2.canAccess(stableQuery, { signal: controller.signal }).then((decision) => {
@@ -797,8 +807,8 @@ function useCanAccess(query) {
797
807
  alive = false;
798
808
  controller.abort();
799
809
  };
800
- }, [app, stableQuery]);
801
- return result;
810
+ }, [auth2, stableQuery]);
811
+ return auth2 ? result : DENIED_NO_AUTH;
802
812
  }
803
813
 
804
814
  // src/components/CanAccess.tsx
@@ -826,12 +836,12 @@ var import_react_redux3 = require("react-redux");
826
836
  var useAppSelector = import_react_redux3.useSelector;
827
837
 
828
838
  // src/hooks/useTranslation.ts
829
- var import_react6 = require("react");
839
+ var import_react7 = require("react");
830
840
  function useTranslation() {
831
841
  const app = useFrontX();
832
842
  const { i18nRegistry: i18nRegistry2 } = app;
833
- const version = (0, import_react6.useSyncExternalStore)(
834
- (0, import_react6.useCallback)(
843
+ const version = (0, import_react7.useSyncExternalStore)(
844
+ (0, import_react7.useCallback)(
835
845
  (callback) => {
836
846
  return i18nRegistry2.subscribe(callback);
837
847
  },
@@ -840,17 +850,17 @@ function useTranslation() {
840
850
  () => i18nRegistry2.getVersion(),
841
851
  () => i18nRegistry2.getVersion()
842
852
  );
843
- const language = (0, import_react6.useMemo)(() => {
853
+ const language = (0, import_react7.useMemo)(() => {
844
854
  void version;
845
855
  return i18nRegistry2.getLanguage();
846
856
  }, [i18nRegistry2, version]);
847
- const t = (0, import_react6.useCallback)(
857
+ const t = (0, import_react7.useCallback)(
848
858
  (key, params) => {
849
859
  return i18nRegistry2.t(key, params);
850
860
  },
851
861
  [i18nRegistry2]
852
862
  );
853
- const setLanguage = (0, import_react6.useCallback)(
863
+ const setLanguage = (0, import_react7.useCallback)(
854
864
  (lang) => {
855
865
  if (app.actions.setLanguage) {
856
866
  app.actions.setLanguage({ language: lang });
@@ -858,7 +868,7 @@ function useTranslation() {
858
868
  },
859
869
  [app.actions]
860
870
  );
861
- const isRTL = (0, import_react6.useMemo)(() => {
871
+ const isRTL = (0, import_react7.useMemo)(() => {
862
872
  void language;
863
873
  return i18nRegistry2.isRTL();
864
874
  }, [i18nRegistry2, language]);
@@ -871,29 +881,28 @@ function useTranslation() {
871
881
  }
872
882
 
873
883
  // src/hooks/useScreenTranslations.ts
874
- var import_react7 = require("react");
884
+ var import_react8 = require("react");
875
885
  function isTranslationLoader(input) {
876
886
  return typeof input === "function";
877
887
  }
878
888
  function useScreenTranslations(screensetId, screenId, translations) {
879
889
  const app = useFrontX();
880
890
  const { i18nRegistry: i18nRegistry2 } = app;
881
- const [loadedLanguage, setLoadedLanguage] = (0, import_react7.useState)(null);
882
- const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
883
- const [error, setError] = (0, import_react7.useState)(null);
884
- const version = (0, import_react7.useSyncExternalStore)(
885
- (0, import_react7.useCallback)(
891
+ const [loadedLanguage, setLoadedLanguage] = (0, import_react8.useState)(null);
892
+ const [error, setError] = (0, import_react8.useState)(null);
893
+ const version = (0, import_react8.useSyncExternalStore)(
894
+ (0, import_react8.useCallback)(
886
895
  (callback) => i18nRegistry2.subscribe(callback),
887
896
  [i18nRegistry2]
888
897
  ),
889
898
  () => i18nRegistry2.getVersion(),
890
899
  () => i18nRegistry2.getVersion()
891
900
  );
892
- const currentLanguage = (0, import_react7.useMemo)(() => {
901
+ const currentLanguage = (0, import_react8.useMemo)(() => {
893
902
  void version;
894
903
  return i18nRegistry2.getLanguage();
895
904
  }, [i18nRegistry2, version]);
896
- const loader = (0, import_react7.useMemo)(() => {
905
+ const loader = (0, import_react8.useMemo)(() => {
897
906
  if (isTranslationLoader(translations)) {
898
907
  return translations;
899
908
  }
@@ -906,12 +915,11 @@ function useScreenTranslations(screensetId, screenId, translations) {
906
915
  return module2.default;
907
916
  };
908
917
  }, [translations]);
909
- (0, import_react7.useEffect)(() => {
918
+ (0, import_react8.useEffect)(() => {
910
919
  if (!currentLanguage || currentLanguage === loadedLanguage) {
911
920
  return;
912
921
  }
913
922
  let cancelled = false;
914
- setIsLoading(true);
915
923
  const loadTranslations = async () => {
916
924
  try {
917
925
  const namespace = `screen.${screensetId}.${screenId}`;
@@ -920,13 +928,11 @@ function useScreenTranslations(screensetId, screenId, translations) {
920
928
  i18nRegistry2.register(namespace, currentLanguage, loadedTranslations);
921
929
  if (!cancelled) {
922
930
  setLoadedLanguage(currentLanguage);
923
- setIsLoading(false);
924
931
  setError(null);
925
932
  }
926
933
  } catch (err) {
927
934
  if (!cancelled) {
928
935
  setError(err instanceof Error ? err : new Error(String(err)));
929
- setIsLoading(false);
930
936
  }
931
937
  }
932
938
  };
@@ -935,16 +941,16 @@ function useScreenTranslations(screensetId, screenId, translations) {
935
941
  cancelled = true;
936
942
  };
937
943
  }, [screensetId, screenId, loader, i18nRegistry2, currentLanguage, loadedLanguage]);
938
- const isLoaded = currentLanguage !== null && currentLanguage === loadedLanguage && !isLoading;
944
+ const isLoaded = currentLanguage !== null && currentLanguage === loadedLanguage;
939
945
  return { isLoaded, error };
940
946
  }
941
947
 
942
948
  // src/hooks/useFormatters.ts
943
- var import_react8 = require("react");
949
+ var import_react9 = require("react");
944
950
  var import_framework4 = require("@gears-frontx/framework");
945
951
  function useFormatters() {
946
952
  const { language } = useTranslation();
947
- return (0, import_react8.useMemo)(
953
+ return (0, import_react9.useMemo)(
948
954
  () => {
949
955
  void language;
950
956
  return {
@@ -965,12 +971,12 @@ function useFormatters() {
965
971
  }
966
972
 
967
973
  // src/hooks/useTheme.ts
968
- var import_react9 = require("react");
974
+ var import_react10 = require("react");
969
975
  function useTheme() {
970
976
  const app = useFrontX();
971
977
  const { themeRegistry } = app;
972
- const version = (0, import_react9.useSyncExternalStore)(
973
- (0, import_react9.useCallback)(
978
+ const version = (0, import_react10.useSyncExternalStore)(
979
+ (0, import_react10.useCallback)(
974
980
  (callback) => {
975
981
  return themeRegistry.subscribe(callback);
976
982
  },
@@ -979,18 +985,18 @@ function useTheme() {
979
985
  () => themeRegistry.getVersion(),
980
986
  () => themeRegistry.getVersion()
981
987
  );
982
- const currentTheme = (0, import_react9.useMemo)(() => {
988
+ const currentTheme = (0, import_react10.useMemo)(() => {
983
989
  void version;
984
990
  const theme = themeRegistry.getCurrent();
985
991
  return theme?.id;
986
992
  }, [themeRegistry, version]);
987
- const themes2 = (0, import_react9.useMemo)(() => {
993
+ const themes2 = (0, import_react10.useMemo)(() => {
988
994
  return themeRegistry.getAll().map((theme) => ({
989
995
  id: theme.id,
990
996
  name: theme.name
991
997
  }));
992
998
  }, [themeRegistry]);
993
- const setTheme = (0, import_react9.useCallback)(
999
+ const setTheme = (0, import_react10.useCallback)(
994
1000
  (themeId) => {
995
1001
  if (app.actions.changeTheme) {
996
1002
  app.actions.changeTheme({ themeId });
@@ -1026,35 +1032,48 @@ function useApiSuspenseInfiniteQuery(options) {
1026
1032
  }
1027
1033
 
1028
1034
  // src/hooks/useApiMutation.ts
1029
- var import_react10 = require("react");
1035
+ var import_react11 = require("react");
1030
1036
  function useApiMutation(options) {
1031
1037
  const queryClient = useRequiredFrontXQueryClient();
1032
- const queryCache2 = (0, import_react10.useMemo)(() => createQueryCache(queryClient), [queryClient]);
1033
- const callbackCtx = (0, import_react10.useMemo)(() => ({ queryCache: queryCache2 }), [queryCache2]);
1038
+ const queryCache2 = (0, import_react11.useMemo)(() => createQueryCache(queryClient), [queryClient]);
1039
+ const callbackCtx = (0, import_react11.useMemo)(() => ({ queryCache: queryCache2 }), [queryCache2]);
1034
1040
  return useFrontXMutation(options, callbackCtx);
1035
1041
  }
1036
1042
 
1037
1043
  // src/hooks/useApiStream.ts
1038
- var import_react11 = require("react");
1044
+ var import_react12 = require("react");
1039
1045
  function useApiStream(descriptor, options) {
1040
1046
  const mode = options?.mode ?? "latest";
1041
1047
  const enabled = options?.enabled ?? true;
1042
- const [data, setData] = (0, import_react11.useState)(void 0);
1043
- const [events, setEvents] = (0, import_react11.useState)([]);
1044
- const [status, setStatus] = (0, import_react11.useState)("idle");
1045
- const [error, setError] = (0, import_react11.useState)(null);
1046
- const connectPromiseRef = (0, import_react11.useRef)(null);
1047
- const connectionIdRef = (0, import_react11.useRef)(null);
1048
- const disconnectRequestedRef = (0, import_react11.useRef)(false);
1049
- const descriptorRef = (0, import_react11.useRef)(descriptor);
1050
- descriptorRef.current = descriptor;
1051
- const descriptorKey = (0, import_react11.useMemo)(() => JSON.stringify(descriptor.key), [descriptor.key]);
1052
- (0, import_react11.useEffect)(() => {
1048
+ const [data, setData] = (0, import_react12.useState)(void 0);
1049
+ const [events, setEvents] = (0, import_react12.useState)([]);
1050
+ const [status, setStatus] = (0, import_react12.useState)(() => enabled ? "connecting" : "idle");
1051
+ const [error, setError] = (0, import_react12.useState)(null);
1052
+ const connectPromiseRef = (0, import_react12.useRef)(null);
1053
+ const connectionIdRef = (0, import_react12.useRef)(null);
1054
+ const disconnectRequestedRef = (0, import_react12.useRef)(false);
1055
+ const descriptorRef = useLatest(descriptor);
1056
+ const descriptorKey = (0, import_react12.useMemo)(() => JSON.stringify(descriptor.key), [descriptor.key]);
1057
+ const resetKey = `${descriptorKey}:${mode}`;
1058
+ const [prevResetKey, setPrevResetKey] = (0, import_react12.useState)(resetKey);
1059
+ if (resetKey !== prevResetKey) {
1060
+ setPrevResetKey(resetKey);
1053
1061
  setData(void 0);
1054
1062
  setEvents([]);
1055
1063
  setError(null);
1056
- }, [descriptorKey, mode]);
1057
- const disconnect = (0, import_react11.useCallback)(() => {
1064
+ }
1065
+ const connectKey = `${resetKey}:${enabled}`;
1066
+ const [prevConnectKey, setPrevConnectKey] = (0, import_react12.useState)(connectKey);
1067
+ if (connectKey !== prevConnectKey) {
1068
+ setPrevConnectKey(connectKey);
1069
+ if (enabled) {
1070
+ setData(void 0);
1071
+ setEvents([]);
1072
+ setStatus("connecting");
1073
+ setError(null);
1074
+ }
1075
+ }
1076
+ const disconnect = (0, import_react12.useCallback)(() => {
1058
1077
  disconnectRequestedRef.current = true;
1059
1078
  if (connectionIdRef.current) {
1060
1079
  descriptorRef.current.disconnect(connectionIdRef.current);
@@ -1062,19 +1081,14 @@ function useApiStream(descriptor, options) {
1062
1081
  disconnectRequestedRef.current = false;
1063
1082
  }
1064
1083
  setStatus("disconnected");
1065
- }, []);
1066
- (0, import_react11.useEffect)(() => {
1084
+ }, [descriptorRef]);
1085
+ (0, import_react12.useEffect)(() => {
1067
1086
  if (!enabled) {
1068
- setStatus("idle");
1069
1087
  return;
1070
1088
  }
1071
1089
  let cancelled = false;
1072
1090
  disconnectRequestedRef.current = false;
1073
1091
  const d = descriptorRef.current;
1074
- setData(void 0);
1075
- setEvents([]);
1076
- setStatus("connecting");
1077
- setError(null);
1078
1092
  const connectPromise = d.connect(
1079
1093
  (event) => {
1080
1094
  if (cancelled) return;
@@ -1120,12 +1134,12 @@ function useApiStream(descriptor, options) {
1120
1134
  connectPromiseRef.current = null;
1121
1135
  connectionIdRef.current = null;
1122
1136
  };
1123
- }, [descriptorKey, enabled, mode]);
1124
- return { data, events, status, error, disconnect };
1137
+ }, [descriptorKey, enabled, mode, descriptorRef]);
1138
+ return { data, events, status: enabled ? status : "idle", error, disconnect };
1125
1139
  }
1126
1140
 
1127
1141
  // src/hooks/useQueryCache.ts
1128
- var import_react12 = require("react");
1142
+ var import_react13 = require("react");
1129
1143
  function useQueryCache() {
1130
1144
  const queryClient = useOptionalFrontXQueryClient();
1131
1145
  if (!queryClient) {
@@ -1133,7 +1147,7 @@ function useQueryCache() {
1133
1147
  "[FrontXProvider] No query cache available. Add queryCache() or queryCacheShared() to your plugin composition."
1134
1148
  );
1135
1149
  }
1136
- return (0, import_react12.useMemo)(() => createQueryCache(queryClient), [queryClient]);
1150
+ return (0, import_react13.useMemo)(() => createQueryCache(queryClient), [queryClient]);
1137
1151
  }
1138
1152
 
1139
1153
  // src/mfe/hooks/useMfeBridge.ts
@@ -1143,31 +1157,31 @@ function useMfeBridge() {
1143
1157
  }
1144
1158
 
1145
1159
  // src/mfe/hooks/useSharedProperty.ts
1146
- var import_react13 = require("react");
1160
+ var import_react14 = require("react");
1147
1161
  function useSharedProperty(propertyTypeId) {
1148
1162
  const { bridge } = useMfeContext();
1149
- const subscribe = (0, import_react13.useCallback)((callback) => {
1163
+ const subscribe = (0, import_react14.useCallback)((callback) => {
1150
1164
  return bridge.subscribeToProperty(propertyTypeId, () => {
1151
1165
  callback();
1152
1166
  });
1153
1167
  }, [bridge, propertyTypeId]);
1154
- const getSnapshot = (0, import_react13.useCallback)(() => {
1168
+ const getSnapshot = (0, import_react14.useCallback)(() => {
1155
1169
  const property = bridge.getProperty(propertyTypeId);
1156
1170
  return property?.value;
1157
1171
  }, [bridge, propertyTypeId]);
1158
- const value = (0, import_react13.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
1172
+ const value = (0, import_react14.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
1159
1173
  return value;
1160
1174
  }
1161
1175
 
1162
1176
  // src/mfe/hooks/useHostAction.ts
1163
- var import_react14 = require("react");
1177
+ var import_react15 = require("react");
1164
1178
  function useHostAction(actionTypeId) {
1165
1179
  const { bridge } = useMfeContext();
1166
- return (0, import_react14.useCallback)((payload) => {
1180
+ return (0, import_react15.useCallback)((payload) => {
1167
1181
  const chain = {
1168
1182
  action: {
1169
1183
  type: actionTypeId,
1170
- target: bridge.domainId,
1184
+ target: bridge.extDomainId,
1171
1185
  payload
1172
1186
  }
1173
1187
  };
@@ -1181,7 +1195,7 @@ function useHostAction(actionTypeId) {
1181
1195
  }
1182
1196
 
1183
1197
  // src/mfe/hooks/useDomainExtensions.ts
1184
- var import_react15 = require("react");
1198
+ var import_react16 = require("react");
1185
1199
  function useDomainExtensions(domainId) {
1186
1200
  const app = useFrontX();
1187
1201
  const registry = app.mfeRegistry;
@@ -1190,14 +1204,14 @@ function useDomainExtensions(domainId) {
1190
1204
  "useDomainExtensions requires the microfrontends plugin. Add microfrontends() to your Gears FrontX app configuration."
1191
1205
  );
1192
1206
  }
1193
- const subscribe = (0, import_react15.useCallback)(
1207
+ const subscribe = (0, import_react16.useCallback)(
1194
1208
  (onStoreChange) => {
1195
1209
  return app.store.subscribe(onStoreChange);
1196
1210
  },
1197
1211
  [app.store]
1198
1212
  );
1199
- const cacheRef = (0, import_react15.useRef)({ ids: "", extensions: [] });
1200
- const getSnapshot = (0, import_react15.useCallback)(() => {
1213
+ const cacheRef = (0, import_react16.useRef)({ ids: "", extensions: [] });
1214
+ const getSnapshot = (0, import_react16.useCallback)(() => {
1201
1215
  const extensions = registry.getExtensionsForDomain(domainId);
1202
1216
  const ids = extensions.map((e) => e.id).join(",");
1203
1217
  if (ids !== cacheRef.current.ids) {
@@ -1205,11 +1219,11 @@ function useDomainExtensions(domainId) {
1205
1219
  }
1206
1220
  return cacheRef.current.extensions;
1207
1221
  }, [registry, domainId]);
1208
- return (0, import_react15.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
1222
+ return (0, import_react16.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
1209
1223
  }
1210
1224
 
1211
1225
  // src/mfe/hooks/useMountedExtensions.ts
1212
- var import_react16 = require("react");
1226
+ var import_react17 = require("react");
1213
1227
  function useMountedExtensions(domainId) {
1214
1228
  const app = useFrontX();
1215
1229
  const registry = app.mfeRegistry;
@@ -1218,14 +1232,14 @@ function useMountedExtensions(domainId) {
1218
1232
  "useMountedExtensions requires the microfrontends plugin. Add microfrontends() to your Gears FrontX app configuration."
1219
1233
  );
1220
1234
  }
1221
- const subscribe = (0, import_react16.useCallback)(
1235
+ const subscribe = (0, import_react17.useCallback)(
1222
1236
  (onStoreChange) => {
1223
1237
  return app.store.subscribe(onStoreChange);
1224
1238
  },
1225
1239
  [app.store]
1226
1240
  );
1227
- const cacheRef = (0, import_react16.useRef)({ key: "", extensions: [] });
1228
- const getSnapshot = (0, import_react16.useCallback)(() => {
1241
+ const cacheRef = (0, import_react17.useRef)({ key: "", extensions: [] });
1242
+ const getSnapshot = (0, import_react17.useCallback)(() => {
1229
1243
  const ids = registry.getMountedExtensions(domainId);
1230
1244
  const resolved = ids.map((id) => registry.getExtension(id)).filter((ext) => ext !== void 0);
1231
1245
  const key = ids.join(",");
@@ -1234,11 +1248,11 @@ function useMountedExtensions(domainId) {
1234
1248
  }
1235
1249
  return cacheRef.current.extensions;
1236
1250
  }, [registry, domainId]);
1237
- return (0, import_react16.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
1251
+ return (0, import_react17.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
1238
1252
  }
1239
1253
 
1240
1254
  // src/mfe/hooks/useRegisteredPackages.ts
1241
- var import_react17 = require("react");
1255
+ var import_react18 = require("react");
1242
1256
  function useRegisteredPackages() {
1243
1257
  const app = useFrontX();
1244
1258
  const registry = app.mfeRegistry;
@@ -1247,14 +1261,14 @@ function useRegisteredPackages() {
1247
1261
  "useRegisteredPackages requires the microfrontends plugin. Add microfrontends() to your Gears FrontX app configuration."
1248
1262
  );
1249
1263
  }
1250
- const subscribe = (0, import_react17.useCallback)(
1264
+ const subscribe = (0, import_react18.useCallback)(
1251
1265
  (onStoreChange) => {
1252
1266
  return app.store.subscribe(onStoreChange);
1253
1267
  },
1254
1268
  [app.store]
1255
1269
  );
1256
- const cacheRef = (0, import_react17.useRef)({ packages: "", list: [] });
1257
- const getSnapshot = (0, import_react17.useCallback)(() => {
1270
+ const cacheRef = (0, import_react18.useRef)({ packages: "", list: [] });
1271
+ const getSnapshot = (0, import_react18.useCallback)(() => {
1258
1272
  const list = registry.getRegisteredPackages();
1259
1273
  const packages = list.join(",");
1260
1274
  if (packages !== cacheRef.current.packages) {
@@ -1262,7 +1276,7 @@ function useRegisteredPackages() {
1262
1276
  }
1263
1277
  return cacheRef.current.list;
1264
1278
  }, [registry]);
1265
- return (0, import_react17.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
1279
+ return (0, import_react18.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
1266
1280
  }
1267
1281
 
1268
1282
  // src/mfe/ThemeAwareReactLifecycle.tsx
@@ -1373,7 +1387,7 @@ var ThemeAwareReactLifecycle = class {
1373
1387
  };
1374
1388
 
1375
1389
  // src/mfe/components/ExtensionDomainSlot.tsx
1376
- var import_react18 = require("react");
1390
+ var import_react19 = require("react");
1377
1391
  var import_jsx_runtime5 = require("react/jsx-runtime");
1378
1392
  function ExtensionDomainSlot(props) {
1379
1393
  const {
@@ -1384,13 +1398,15 @@ function ExtensionDomainSlot(props) {
1384
1398
  onDetached,
1385
1399
  loadingComponent = null
1386
1400
  } = props;
1387
- const rootRef = (0, import_react18.useRef)(null);
1388
- const onAttachedRef = (0, import_react18.useRef)(onAttached);
1389
- const onDetachedRef = (0, import_react18.useRef)(onDetached);
1390
- onAttachedRef.current = onAttached;
1391
- onDetachedRef.current = onDetached;
1392
- const [attached, setAttached] = (0, import_react18.useState)(false);
1393
- (0, import_react18.useEffect)(() => {
1401
+ const rootRef = (0, import_react19.useRef)(null);
1402
+ const emitAttached = (0, import_react19.useEffectEvent)((root) => {
1403
+ onAttached?.(root);
1404
+ });
1405
+ const emitDetached = (0, import_react19.useEffectEvent)(() => {
1406
+ onDetached?.();
1407
+ });
1408
+ const [attached, setAttached] = (0, import_react19.useState)(false);
1409
+ (0, import_react19.useEffect)(() => {
1394
1410
  const root = rootRef.current;
1395
1411
  if (!root) {
1396
1412
  return;
@@ -1398,11 +1414,11 @@ function ExtensionDomainSlot(props) {
1398
1414
  const mounter = registry.getMounter(domainId);
1399
1415
  mounter.attach(root);
1400
1416
  setAttached(true);
1401
- onAttachedRef.current?.(root);
1417
+ emitAttached(root);
1402
1418
  return () => {
1403
1419
  void mounter.detach();
1404
1420
  setAttached(false);
1405
- onDetachedRef.current?.();
1421
+ emitDetached();
1406
1422
  };
1407
1423
  }, [registry, domainId]);
1408
1424
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(