@pylonsync/functions 0.22.33 → 0.22.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.
package/package.json
CHANGED
|
@@ -804,3 +804,14 @@ describe("nearestBoundaryComponent across route groups", () => {
|
|
|
804
804
|
).toBe("app/(marketing)/not-found");
|
|
805
805
|
});
|
|
806
806
|
});
|
|
807
|
+
|
|
808
|
+
describe("client router popstate", () => {
|
|
809
|
+
test("a hash-only popstate does not re-render the route", () => {
|
|
810
|
+
// Clicking a same-page anchor fires popstate. Treating it as a navigation
|
|
811
|
+
// re-rendered the page and scrolled back to the top.
|
|
812
|
+
const src = fs.readFileSync(path.join(import.meta.dir, "ssr-client-bundler.ts"), "utf8");
|
|
813
|
+
const popstate = src.slice(src.indexOf('window.addEventListener("popstate"'));
|
|
814
|
+
expect(popstate).toContain("if (next === renderedPath) return;");
|
|
815
|
+
expect(src.match(/renderedPath = location\.pathname \+ location\.search;/g)?.length).toBeGreaterThanOrEqual(3);
|
|
816
|
+
});
|
|
817
|
+
});
|
|
@@ -830,6 +830,12 @@ function renderPendingPlaceholder(pathname, manifest, myEpoch) {
|
|
|
830
830
|
return true;
|
|
831
831
|
}
|
|
832
832
|
|
|
833
|
+
// The path and query the page last rendered. A popstate that keeps them and
|
|
834
|
+
// only changes the hash is a same-page jump (an anchor link, a back press
|
|
835
|
+
// between anchors), not a navigation: re-rendering for it would reset the
|
|
836
|
+
// scroll to the top.
|
|
837
|
+
let renderedPath = "";
|
|
838
|
+
|
|
833
839
|
async function navigate(href, opts) {
|
|
834
840
|
const push = !opts || opts.push !== false;
|
|
835
841
|
const url = new URL(href, location.href);
|
|
@@ -891,6 +897,7 @@ async function navigate(href, opts) {
|
|
|
891
897
|
history.pushState({ component: matched.component }, "", target);
|
|
892
898
|
}
|
|
893
899
|
window.dispatchEvent(new Event("pylon:navigation"));
|
|
900
|
+
renderedPath = location.pathname + location.search;
|
|
894
901
|
window.scrollTo(0, 0);
|
|
895
902
|
didOptimistic = true;
|
|
896
903
|
}
|
|
@@ -915,6 +922,7 @@ async function navigate(href, opts) {
|
|
|
915
922
|
loadManifest().then((manifest) => {
|
|
916
923
|
if (navState.settled || myEpoch !== navEpoch) return;
|
|
917
924
|
if (renderPendingPlaceholder(url.pathname, manifest, myEpoch)) {
|
|
925
|
+
renderedPath = location.pathname + location.search;
|
|
918
926
|
window.scrollTo(0, 0);
|
|
919
927
|
}
|
|
920
928
|
});
|
|
@@ -1013,6 +1021,7 @@ async function navigate(href, opts) {
|
|
|
1013
1021
|
// re-read location after a Link click or a router.push(). popstate already
|
|
1014
1022
|
// covers back/forward, but pushState/replaceState fire no event.
|
|
1015
1023
|
window.dispatchEvent(new Event("pylon:navigation"));
|
|
1024
|
+
renderedPath = location.pathname + location.search;
|
|
1016
1025
|
// After a successful nav, scroll to top (Next.js default).
|
|
1017
1026
|
window.scrollTo(0, 0);
|
|
1018
1027
|
}
|
|
@@ -1042,8 +1051,11 @@ function installNavHandlers() {
|
|
|
1042
1051
|
const seed = seeds ? seeds.get(link) : undefined;
|
|
1043
1052
|
navigate(href, seed != null ? { seed } : undefined);
|
|
1044
1053
|
});
|
|
1054
|
+
renderedPath = location.pathname + location.search;
|
|
1045
1055
|
window.addEventListener("popstate", () => {
|
|
1046
|
-
|
|
1056
|
+
const next = location.pathname + location.search;
|
|
1057
|
+
if (next === renderedPath) return;
|
|
1058
|
+
navigate(next, { push: false });
|
|
1047
1059
|
});
|
|
1048
1060
|
// Progressive-enhancement form submit (#276): intercept <form data-pylon-form>
|
|
1049
1061
|
// so the page doesn't full-reload. fetch the same route.ts endpoint, follow
|