@jsenv/navi 0.29.497 → 0.29.498

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.
@@ -10024,8 +10024,8 @@ const suspendScrollRecording = () => {
10024
10024
  // the reader reaching for the page: where they are is theirs (see
10025
10025
  // installScrollRestoration).
10026
10026
  let pendingRestoration = null;
10027
- const startRestoration = (position) => {
10028
- const restoration = { position, due: false };
10027
+ const startRestoration = (position, { meanwhile = false } = {}) => {
10028
+ const restoration = { position, due: false, meanwhile };
10029
10029
  pendingRestoration = restoration;
10030
10030
  return restoration;
10031
10031
  };
@@ -10038,6 +10038,7 @@ const putBack = (restoration) => {
10038
10038
  restoration.due = true;
10039
10039
  if (restorationHoldCount) {
10040
10040
  // The page is not whole yet: the last release puts it back.
10041
+ putBackMeanwhile(restoration);
10041
10042
  return;
10042
10043
  }
10043
10044
  if (isDocumentHeld()) {
@@ -10084,6 +10085,24 @@ const isDocumentHeld = () => {
10084
10085
  return false;
10085
10086
  };
10086
10087
 
10088
+ // A return is photographed by its route transition as soon as its page has
10089
+ // rendered, stand-ins and all, and a position waiting for the page to be whole
10090
+ // is written after the movement, seen as a jump. So it is also written into
10091
+ // what is there meanwhile, as far as that goes — the browser clamps the rest —
10092
+ // and again once the page is whole, when what it stands on has grown or shrunk.
10093
+ const putBackMeanwhile = (restoration) => {
10094
+ if (!restoration.meanwhile) {
10095
+ return;
10096
+ }
10097
+ // Out of whatever commit or effect is asking: see scrollTo.
10098
+ queueMicrotask(() => {
10099
+ if (pendingRestoration !== restoration || isDocumentHeld()) {
10100
+ return;
10101
+ }
10102
+ scrollTo(restoration.position);
10103
+ });
10104
+ };
10105
+
10087
10106
  // What a page holds instead: not the place, which stays the url's, but the
10088
10107
  // moment it is put back (see useHoldScrollRestoration). Counted: several parts
10089
10108
  // of one page can be waiting.
@@ -10227,6 +10246,7 @@ const putBackOnceAnswered = (restoration) => {
10227
10246
  });
10228
10247
  return;
10229
10248
  }
10249
+ putBackMeanwhile(restoration);
10230
10250
  // A reader drawing its own wait subscribes in an effect, after the first
10231
10251
  // paint (see afterPaint): an answer that came before is drawn only then.
10232
10252
  let waitCount = 2;
@@ -10350,11 +10370,12 @@ const restoreScrollPosition = (url) => {
10350
10370
  };
10351
10371
 
10352
10372
  // A traversal back to `url`. The offset is written once the page returned to is
10353
- // rendered and answered (see putBackOnceAnswered): written sooner, the document
10354
- // still holds the page being left, or a stand-in for the one arriving, and
10355
- // clamps it to that height. It is read at once all the same — a page left
10356
- // taller than the one arriving is clamped by the render itself, and that clamp
10357
- // is a scroll recorded under the url already returned to.
10373
+ // rendered (see whenPageRendered): written sooner, the document still holds the
10374
+ // page being left and clamps it to that height. Again once it has answered (see
10375
+ // putBackOnceAnswered), when it rendered stand-ins (see putBackMeanwhile). It
10376
+ // is read at once all the same — a page left taller than the one arriving is
10377
+ // clamped by the render itself, and that clamp is a scroll recorded under the
10378
+ // url already returned to.
10358
10379
  const restoreScrollPositionOnReturn = (url) => {
10359
10380
  pendingRestoration = null;
10360
10381
  const href = new URL(url, window.location.href).href;
@@ -10363,7 +10384,7 @@ const restoreScrollPositionOnReturn = (url) => {
10363
10384
  if (!position) {
10364
10385
  return;
10365
10386
  }
10366
- const restoration = startRestoration(position);
10387
+ const restoration = startRestoration(position, { meanwhile: true });
10367
10388
  whenPageRendered(() => {
10368
10389
  putBackOnceAnswered(restoration);
10369
10390
  });