@jsenv/navi 0.29.235 → 0.29.236

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.
@@ -6034,6 +6034,7 @@ installImportMetaCssBuild(import.meta);
6034
6034
  let calloutCount = 0;
6035
6035
 
6036
6036
  const css$13 = /* css */ `
6037
+ /* jsenv-css-opaque: same as dialog.jsx, cascade order. */
6037
6038
  @layer navi {
6038
6039
  .navi_callout {
6039
6040
  /* A callout is parented to what it explains, so it inherits from it — and
@@ -26130,6 +26131,47 @@ const resolveEffectiveDocumentState = (
26130
26131
  return { ...state, ...sharedState };
26131
26132
  };
26132
26133
 
26134
+ // Preact's own useId() (see preact/hooks) returns "P<mask0>-<mask1>", where the
26135
+ // mask is derived from render order within the nearest root/async boundary:
26136
+ // stable across re-renders of the same mount, but not across two mounts on the
26137
+ // same page, and not across two documents.
26138
+ const PREACT_GENERATED_ID_REGEX = /^P\d+-\d+/;
26139
+ const isLikelyPreactGeneratedId = (id) => {
26140
+ return PREACT_GENERATED_ID_REGEX.test(id);
26141
+ };
26142
+
26143
+ /**
26144
+ * A history entry outlives the document that wrote it: `history.state` comes
26145
+ * back as it was left on a reload, and on a back/forward into a document that
26146
+ * has been unloaded since.
26147
+ *
26148
+ * A key named by a generated id names a position in the render order of the
26149
+ * document that wrote it, and nothing else. Read back in another document the
26150
+ * same key names whatever now renders at that position — so an open popup left
26151
+ * behind by the previous document opens a component nobody ever touched (see
26152
+ * `useNavState`, whose key presence IS the open state). Only a caller-given id
26153
+ * means the same thing on both sides of a load.
26154
+ *
26155
+ * Returns the state untouched when it holds no such key, so the caller can tell
26156
+ * whether the entry needs rewriting.
26157
+ */
26158
+ const dropGeneratedIdKeys = (state) => {
26159
+ if (!state) {
26160
+ return state;
26161
+ }
26162
+ let stateWithoutGeneratedIdKeys = state;
26163
+ for (const key of Object.keys(state)) {
26164
+ if (!isLikelyPreactGeneratedId(key)) {
26165
+ continue;
26166
+ }
26167
+ if (stateWithoutGeneratedIdKeys === state) {
26168
+ stateWithoutGeneratedIdKeys = { ...state };
26169
+ }
26170
+ delete stateWithoutGeneratedIdKeys[key];
26171
+ }
26172
+ return stateWithoutGeneratedIdKeys;
26173
+ };
26174
+
26133
26175
  /**
26134
26176
  * The document's rendering, held for the one frame a view transition needs.
26135
26177
  *
@@ -26986,7 +27028,14 @@ const setupBrowserIntegrationViaHistory = ({
26986
27028
 
26987
27029
  const init = () => {
26988
27030
  const url = window.location.href;
26989
- const state = history.state;
27031
+ const stateOnEntry = window.history.state;
27032
+ const state = dropGeneratedIdKeys(stateOnEntry);
27033
+ if (state !== stateOnEntry) {
27034
+ // The entry itself has to lose them too, not just the document state:
27035
+ // getDocumentState() reads the entry back, and every state write copies
27036
+ // what it finds there onto the next one.
27037
+ window.history.replaceState(state, null, url);
27038
+ }
26990
27039
  handleRoutingTask(url, {
26991
27040
  reason: "routing initialization",
26992
27041
  navigationType: "load",
@@ -27220,18 +27269,6 @@ Consider using unique IDs for each component instance.`,
27220
27269
  return useNavStateBasic(id, options);
27221
27270
  };
27222
27271
 
27223
- // Preact's own useId() (see preact/hooks) returns "P<mask0>-<mask1>", where
27224
- // the mask is derived from render order within the nearest root/async
27225
- // boundary — stable across re-renders of the *same* mount, but not across a
27226
- // reload (render order can differ) or even across two mounts on the same
27227
- // page (two components hitting useId() in the same relative order get the
27228
- // same string). Storing one of these under type: "push" bakes it into a
27229
- // history entry: reload the page and the entry's key may now belong to a
27230
- // completely different component (or none), silently auto-opening whatever
27231
- // happens to render at that same position instead.
27232
- const PREACT_GENERATED_ID_REGEX = /^P\d+-\d+/;
27233
- const isLikelyPreactGeneratedId = (id) => PREACT_GENERATED_ID_REGEX.test(id);
27234
-
27235
27272
  const NO_OP = () => {};
27236
27273
  const NO_ID_GIVEN = [undefined, NO_OP, NO_OP];
27237
27274
  const useNavStateBasic = (
@@ -27263,6 +27300,10 @@ const useNavStateBasic = (
27263
27300
  }
27264
27301
 
27265
27302
  let effectiveType = type;
27303
+ // A push bakes the key into a history entry of its own, and an id naming a
27304
+ // render position (see isLikelyPreactGeneratedId) can be claimed by two
27305
+ // mounts of this same page. A replace keeps the key on the entry the document
27306
+ // is already on, where the id at least names one render.
27266
27307
  if (type === "push" && isLikelyPreactGeneratedId(id)) {
27267
27308
  {
27268
27309
  console.warn(
@@ -58569,6 +58610,8 @@ const PopupClose = ({
58569
58610
  installImportMetaCssBuild(import.meta);
58570
58611
  let openLocalDialogCount = 0;
58571
58612
  const css$E = /* css */`
58613
+ /* jsenv-css-opaque: popupCss overlaps these rules, own sheet = cascade
58614
+ order depending on which popup renders first. */
58572
58615
  @layer navi {
58573
58616
  .navi_dialog {
58574
58617
  /* Min gap between the dialog and the edges of its container. Written
@@ -60342,6 +60385,8 @@ Dialog.Close = PopupClose;
60342
60385
  installImportMetaCssBuild(import.meta);
60343
60386
  let openLocalPopoverCount = 0;
60344
60387
  const css$D = /* css */`
60388
+ /* jsenv-css-opaque: popupCss overlaps these rules, own sheet = cascade
60389
+ order depending on which popup renders first. */
60345
60390
  @layer navi {
60346
60391
  .navi_popover {
60347
60392
  /* soft: user-configurable preferred max-height. Kept as a *default*