@sladg/apex-state 3.0.3 → 3.0.5

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
@@ -852,6 +852,11 @@ var is = {
852
852
  var pathCache = /* @__PURE__ */ new Map();
853
853
  var MAX_CACHE_SIZE = 1e3;
854
854
  var getPathParts = (path) => {
855
+ if (typeof path !== "string") {
856
+ throw new TypeError(
857
+ `[apex-state] Path must be a string, received ${typeof path}: ${JSON.stringify(path)}. Paths must be dot-notation strings like "user.email" or "items.0.name".`
858
+ );
859
+ }
855
860
  let parts = pathCache.get(path);
856
861
  if (!parts) {
857
862
  parts = path.split(".");
@@ -2660,7 +2665,6 @@ var createProvider = (storeConfig) => {
2660
2665
  initialState: rawInitialState,
2661
2666
  children
2662
2667
  }) => {
2663
- const [wasmReady, setWasmReady] = useState(isLegacy || isWasmLoaded());
2664
2668
  const prepared = useMemo(
2665
2669
  () => prepareInitialState(rawInitialState),
2666
2670
  // Only initialize once - ignore changes to initialState after mount
@@ -2693,26 +2697,37 @@ var createProvider = (storeConfig) => {
2693
2697
  _debug: debugTrack ? ref(debugTrack) : null
2694
2698
  };
2695
2699
  }, []);
2700
+ const [ready, setReady] = useState(
2701
+ () => isLegacy || store._internal.pipeline !== null
2702
+ );
2696
2703
  useEffect(() => {
2697
- if (isLegacy || isWasmLoaded()) return;
2698
- loadWasm2().then(() => {
2699
- initPipeline(
2700
- store._internal,
2701
- prepared.initialState
2702
- );
2703
- setWasmReady(true);
2704
- }).catch((error) => {
2705
- console.error("[apex-state] Failed to load WASM:", error);
2706
- throw error;
2707
- });
2708
- }, []);
2709
- useEffect(() => {
2704
+ if (isLegacy) return;
2705
+ let cancelled = false;
2706
+ const ensurePipeline = () => {
2707
+ if (cancelled) return;
2708
+ if (!store._internal.pipeline) {
2709
+ initPipeline(
2710
+ store._internal,
2711
+ prepared.initialState
2712
+ );
2713
+ }
2714
+ setReady(true);
2715
+ };
2716
+ if (isWasmLoaded()) {
2717
+ ensurePipeline();
2718
+ } else {
2719
+ loadWasm2().then(ensurePipeline).catch((error) => {
2720
+ console.error("[apex-state] Failed to load WASM:", error);
2721
+ });
2722
+ }
2710
2723
  return () => {
2724
+ cancelled = true;
2711
2725
  store._internal.pipeline?.destroy();
2712
2726
  store._internal.pipeline = null;
2727
+ setReady(false);
2713
2728
  };
2714
2729
  }, []);
2715
- if (!wasmReady) {
2730
+ if (!ready) {
2716
2731
  return null;
2717
2732
  }
2718
2733
  return /* @__PURE__ */ jsx(