{"record":{"id":"76787266506276b5","repo":"sveltejs/kit","slug":"replacestate-is-deprecated-use-goto-url","errorCode":null,"errorMessage":"`replaceState(...)` is deprecated. Use `goto(url, { state, shallow: true, replace: true })` instead.","messagePattern":"`replaceState\\(\\.\\.\\.\\)` is deprecated\\. Use `goto\\(url, (.+?)\\)` instead\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/kit/src/runtime/client/client.js","lineNumber":2942,"sourceCode":"\t\tintent,\n\t\tstate,\n\t\t{ replace: false, persist_state: false, reset: false },\n\t\t'pushState'\n\t);\n}\n\n/**\n * Programmatically replace the current history entry with the given `page.state`. Used for [shallow routing](https://svelte.dev/docs/kit/shallow-routing).\n *\n * @deprecated Use `goto(url, { state, shallow: true, replace: true })` instead.\n * @param {string | URL} url\n * @param {App.PageState} state\n * @returns {Promise<void>}\n */\nexport async function replaceState(url, state) {\n\tif (DEV && !warned_on_replace_state_function) {\n\t\twarned_on_replace_state_function = true;\n\t\tconsole.warn(\n\t\t\t'`replaceState(...)` is deprecated. Use `goto(url, { state, shallow: true, replace: true })` instead.'\n\t\t);\n\t}\n\n\tconst intent = await resolve_intent(url, 'replaceState');\n\n\tawait update_state(\n\t\tintent,\n\t\tstate,\n\t\t{ replace: true, persist_state: false, reset: false },\n\t\t'replaceState'\n\t);\n}\n\n/**\n * @param {NavigationIntent} intent\n * @param {App.PageState} state\n * @param {{ replace: boolean; persist_state: boolean; reset: boolean; }} options","sourceCodeStart":2924,"sourceCodeEnd":2960,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/client/client.js#L2924-L2960","documentation":"SvelteKit's client runtime emits this DEV-only console warning when the exported `replaceState(url, state)` function is called. It is superseded by `goto(url, { state, shallow: true, replace: true })`, which replaces the current history entry instead of pushing a new one. The call still works; this is purely a migration warning.","triggerScenarios":"Calling `replaceState(url, state)` from `@sveltejs/kit` in client code (e.g. syncing URL to form/filter state) during development, first use per page load.","commonSituations":"Older codebases using replaceState to keep URL/state in sync without creating history entries (search inputs, wizard steps) after upgrading SvelteKit.","solutions":["Replace `replaceState(url, state)` with `goto(url, { state, shallow: true, replace: true })`","Confirm behavior is identical (history entry replaced, `page.state` updated)","Remove leftover pushState/replaceState imports"],"exampleFix":"// before\nimport { replaceState } from '$app/navigation';\nreplaceState('?page=2', { page: 2 });\n// after\nimport { goto } from '$app/navigation';\ngoto('?page=2', { state: { page: 2 }, shallow: true, replace: true });","handlingStrategy":"validation","validationCode":"if (DEV && /replaceState\\s*\\(/.test(source)) console.warn('replace replaceState with goto replace:true');","typeGuard":"const usesReplaceState = (src) => /\\breplaceState\\s*\\(/.test(src);","tryCatchPattern":null,"preventionTips":["Prefer goto(url, { state, shallow: true, replace: true }) for history-replacing shallow updates","Grep codebase for replaceState after upgrades","Document the goto options API as the single navigation entry point"],"tags":["deprecation","shallow-routing","client","sveltekit"],"backgroundTag":"deprecated-api-usage","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}