Skip to content

Conversation

@5unnyWind
Copy link
Contributor

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Comment on lines +29 to +40
if (location.protocol === "data:") {
const newHash = "#/" + to.replace(/^#?\/?/, "");
newHistoryStatePath = newHash;
newURL = oldURL.split("#")[0] + newHash;
} else {
const [hash, search] = to.replace(/^#?\/?/, "").split("?");
newHistoryStatePath =
location.pathname +
(search ? `?${search}` : location.search) +
`#/${hash}`;
newURL = new URL(newHistoryStatePath, location.origin).href;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for submitting this PR. I've got a theory that if we just change the URL constructor code, we will be able to fix this without handling a special case when the protocol is :data

Image

Something like:

    const [hash, search] = to.replace(/^#?\/?/, "").split("?");

    const newRelativePath =
      location.pathname + (search ? `?${search}` : location.search) + `#/${hash}`;
    const oldURL = location.href;

    // Works for ALL protocols including data:
    const url = new URL(location.href);
    url.hash = `/${hash}`;
    if (search) url.search = search;
    const newURL = url.href;

Could you please check if this is something we could use?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, nevermind. I'm going to merge this and refactor separately. Thanks!

@molefrog molefrog merged commit 28e229a into molefrog:v3 Nov 24, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants