@thoughtbot/superglue 2.0.0-alpha.4 → 2.0.0-alpha.7

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.
@@ -33,7 +33,7 @@ import {
33
33
  ujsHandlers,
34
34
  unproxy,
35
35
  urlToPageKey
36
- } from "./chunk-I4A45IH4.mjs";
36
+ } from "./chunk-Q76JBI63.mjs";
37
37
 
38
38
  // node_modules/lodash/lodash.js
39
39
  var require_lodash = __commonJS({
@@ -5527,14 +5527,12 @@ import { useState, useEffect, useRef as useRef2, createContext, useContext } fro
5527
5527
  import { useSelector as useSelector3 } from "react-redux";
5528
5528
 
5529
5529
  // lib/hooks/useContent.tsx
5530
- import { useSelector } from "react-redux";
5530
+ import { useSelector, useStore } from "react-redux";
5531
5531
  import { useMemo, useRef } from "react";
5532
5532
  function useContent(fragmentRef, options) {
5533
5533
  const superglueState = useSuperglue();
5534
5534
  const currentPageKey = superglueState.currentPageKey;
5535
5535
  const dependencies = useRef(/* @__PURE__ */ new Set());
5536
- const fragmentsHookRef = useRef({});
5537
- const proxyCache = useRef(/* @__PURE__ */ new WeakMap());
5538
5536
  const fragmentId = typeof fragmentRef === "string" ? fragmentRef : fragmentRef?.__id;
5539
5537
  const sourceData = useSelector((state) => {
5540
5538
  if (fragmentId) {
@@ -5543,7 +5541,7 @@ function useContent(fragmentRef, options) {
5543
5541
  return state.pages[currentPageKey].data;
5544
5542
  }
5545
5543
  });
5546
- const fragments = useSelector(
5544
+ const trackedFragments = useSelector(
5547
5545
  (state) => state.fragments,
5548
5546
  (oldFragments, newFragments) => {
5549
5547
  if (oldFragments === newFragments) {
@@ -5556,9 +5554,10 @@ function useContent(fragmentRef, options) {
5556
5554
  });
5557
5555
  }
5558
5556
  );
5559
- fragmentsHookRef.current = fragments;
5560
5557
  const raiseOnMissing = !(options?.optional ?? false);
5558
+ const store = useStore();
5561
5559
  const proxy = useMemo(() => {
5560
+ const proxyCache = /* @__PURE__ */ new WeakMap();
5562
5561
  if (fragmentId && !sourceData) {
5563
5562
  if (raiseOnMissing) {
5564
5563
  throw new Error(`Fragment with id "${fragmentId}" not found`);
@@ -5568,11 +5567,11 @@ function useContent(fragmentRef, options) {
5568
5567
  }
5569
5568
  return createProxy(
5570
5569
  sourceData,
5571
- fragmentsHookRef,
5570
+ { current: store.getState().fragments },
5572
5571
  dependencies.current,
5573
- proxyCache.current
5572
+ proxyCache
5574
5573
  );
5575
- }, [sourceData, options?.optional]);
5574
+ }, [sourceData, trackedFragments, options?.optional]);
5576
5575
  return proxy;
5577
5576
  }
5578
5577
  function unproxy2(proxy) {
@@ -5689,7 +5688,7 @@ import React, {
5689
5688
  forwardRef,
5690
5689
  useImperativeHandle
5691
5690
  } from "react";
5692
- import { useDispatch as useDispatch2, useSelector as useSelector4, useStore } from "react-redux";
5691
+ import { useDispatch as useDispatch2, useSelector as useSelector4, useStore as useStore2 } from "react-redux";
5693
5692
  var NavigationContext = createContext2(
5694
5693
  {}
5695
5694
  );
@@ -5716,7 +5715,7 @@ var NavigationProvider = forwardRef(function NavigationProvider2({ history, visi
5716
5715
  const currentPageKey = useSelector4(
5717
5716
  (state) => state.superglue.currentPageKey
5718
5717
  );
5719
- const store = useStore();
5718
+ const store = useStore2();
5720
5719
  useEffect2(() => {
5721
5720
  return history.listen(onHistoryChange);
5722
5721
  }, []);
@@ -6060,7 +6059,21 @@ var rootReducer = {
6060
6059
  };
6061
6060
 
6062
6061
  // lib/index.tsx
6063
- var cable = createConsumer();
6062
+ function getConfig(name) {
6063
+ if (typeof document !== "undefined") {
6064
+ const element = document.head.querySelector(
6065
+ `meta[name='action-cable-${name}']`
6066
+ );
6067
+ if (element) {
6068
+ return element.getAttribute("content") || "/cable";
6069
+ } else {
6070
+ return "/cable";
6071
+ }
6072
+ } else {
6073
+ return "/cable";
6074
+ }
6075
+ }
6076
+ var cable = createConsumer(getConfig("url"));
6064
6077
  var hasWindow2 = typeof window !== "undefined";
6065
6078
  var createHistory = () => {
6066
6079
  if (hasWindow2) {