@metron-labs/quote-react 0.1.33 → 0.1.34

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.
@@ -103,7 +103,7 @@ function QuickQuoteInner({ fullPage = false, hideHeader = false, internal = fals
103
103
  window.history[stale ? "replaceState" : "pushState"]({ boqQuoteStage: next }, "", url);
104
104
  }, []);
105
105
  useEffect(() => {
106
- const onPopState = () => {
106
+ const onPopState = (event) => {
107
107
  const hash = window.location.hash;
108
108
  if (hash === "#quote-request")
109
109
  setStage("basket");
@@ -112,14 +112,16 @@ function QuickQuoteInner({ fullPage = false, hideHeader = false, internal = fals
112
112
  else
113
113
  setStage("entry");
114
114
  // Turbo's popstate listener (registered before ours, so it can't be pre-empted) stamps its
115
- // restoration id over our entries. On the next back/forward it then treats them as its own
116
- // page visits and reloads the page, dropping the user on entry. Put our state back once
117
- // every listener has run.
115
+ // restoration id over any entry without one - ours, or the host's own entry for this page.
116
+ // On the next back/forward it then treats that entry as its page visit and re-renders the
117
+ // page, wiping the quote. Once every listener has run, undo the stamp.
118
+ const original = event.state;
119
+ const href = window.location.href;
118
120
  setTimeout(() => {
119
- const current = window.location.hash;
120
- if (current !== "#quote-request" && current !== "#matched-products")
121
+ if (original?.turbo || window.location.href !== href)
121
122
  return;
122
- window.history.replaceState({ boqQuoteStage: current === "#quote-request" ? "basket" : "results" }, "", window.location.href);
123
+ if (window.history.state?.turbo)
124
+ window.history.replaceState(original, "", href);
123
125
  });
124
126
  };
125
127
  window.addEventListener("popstate", onPopState);