Verified against @stacksjs/stx at 0.2.153 (local build of main, HEAD 0dcb6fbd0e).
TL;DR
navigate()'s second parameter is declared as an options object with a replace flag. The implementation takes a boolean forceReload. The declared call compiles, and then does the opposite of what it says: a full document load that pushes a history entry, rather than a client-side replace.
Declared
packages/stx/stx.d.ts:101 (hand-written; copied verbatim to dist/stx.d.ts):
declare function navigate(_url: string, _options?: { replace?: boolean }): voidImplemented
packages/stx/src/signals.ts:1027:
function navigate(url, forceReload) {
if (forceReload) {
window.location.href = url;
return;
}
if (window.stxRouter && typeof window.stxRouter.navigate === 'function') {
window.stxRouter.navigate(url);
…There is no replace behaviour anywhere in this function.
Why it matters
navigate is in STX_AUTO_IMPORTS (src/client-script.ts:316), so this ambient declaration is the contract a <script client> author writes against.
navigate('/dashboard', { replace: true })- type-checks cleanly
{ replace: true }is a truthy object, so it takes theforceReloadbranch- result:
window.location.href = url— a full page load, which adds a history entry
So the one call the type system invites is the one that both defeats the SPA router and produces the opposite history behaviour from the one requested. It fails silently — no error, just a slower navigation and a wrong back-button stack.
Suggested fix
Whichever direction is intended, the two should agree. If the boolean is the API:
declare function navigate(_url: string, _forceReload?: boolean): voidIf replace is the intended API, it needs implementing — window.location.replace(url) for the full-load path, and history.replaceState for the router path.
Worth noting there is a second, unrelated navigate at packages/stx/src/composables/use-router.ts:41 with the signature navigate(url: string): void. Two exported functions of the same name and different arities is its own source of confusion, though not what this issue is about.
Related
Same class as #1707 / #1796 / #1797 and the useSearchParams mismatch I filed alongside this one — shipped declarations disagreeing with their implementations.