fix: keep ?fresh-partial an implementation detail (#3776)
When encountering redirect during route change with partials enabled, url in address bar (history api) is being left as ?fresh-partial=true, this doesn't seem right --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
@@ -83,7 +83,7 @@ if (!history.state) {
|
||||
history.replaceState(state, document.title);
|
||||
}
|
||||
|
||||
function maybeUpdateHistory(nextUrl: URL) {
|
||||
function maybePushHistory(nextUrl: URL) {
|
||||
// Only add history entry when URL is new. Still apply
|
||||
// the partials because sometimes users click a link to
|
||||
// "refresh" the current page.
|
||||
@@ -106,6 +106,12 @@ function maybeUpdateHistory(nextUrl: URL) {
|
||||
}
|
||||
}
|
||||
|
||||
function maybeReplaceHistory(nextUrl: URL) {
|
||||
if (nextUrl.href !== globalThis.location.href) {
|
||||
history.replaceState(history.state, "", nextUrl.href);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("click", async (e) => {
|
||||
let el = e.target;
|
||||
if (el && (el instanceof HTMLElement || el instanceof SVGElement)) {
|
||||
@@ -154,7 +160,7 @@ document.addEventListener("click", async (e) => {
|
||||
|
||||
const nextUrl = new URL(el.href);
|
||||
try {
|
||||
maybeUpdateHistory(nextUrl);
|
||||
maybePushHistory(nextUrl);
|
||||
|
||||
const partialUrl = new URL(
|
||||
partial ? partial : nextUrl.href,
|
||||
@@ -361,6 +367,7 @@ async function fetchPartials(
|
||||
actualUrl = nextUrl;
|
||||
}
|
||||
}
|
||||
actualUrl.searchParams.delete(PARTIAL_SEARCH_PARAM);
|
||||
|
||||
try {
|
||||
await applyPartials(res);
|
||||
@@ -375,7 +382,7 @@ async function fetchPartials(
|
||||
}
|
||||
|
||||
if (shouldNavigate) {
|
||||
maybeUpdateHistory(actualUrl);
|
||||
maybeReplaceHistory(actualUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user