diff --git a/.changeset/clean-countries-push.md b/.changeset/clean-countries-push.md new file mode 100644 index 000000000000..1a2d4d7e9169 --- /dev/null +++ b/.changeset/clean-countries-push.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +Set `$page.url` to current URL in browser diff --git a/packages/adapter-static/package.json b/packages/adapter-static/package.json index 0be49ceb5176..fd20c31dfa92 100644 --- a/packages/adapter-static/package.json +++ b/packages/adapter-static/package.json @@ -29,6 +29,7 @@ }, "devDependencies": { "@sveltejs/kit": "workspace:*", + "devalue": "^2.0.1", "playwright-chromium": "^1.17.0", "port-authority": "^1.1.2", "sirv": "^2.0.0", diff --git a/packages/adapter-static/test/utils.js b/packages/adapter-static/test/utils.js index fb3662de19c0..53ea9f0fb7ea 100644 --- a/packages/adapter-static/test/utils.js +++ b/packages/adapter-static/test/utils.js @@ -29,7 +29,8 @@ export function run(app, callback) { suite.before(async (context) => { try { const cwd = fileURLToPath(new URL(`apps/${app}`, import.meta.url)); - const cli_path = fileURLToPath(new URL('../../kit/dist/cli.js', import.meta.url)); + const mode = process.env.CI ? 'dist' : 'src'; + const cli_path = fileURLToPath(new URL(`../../kit/${mode}/cli.js`, import.meta.url)); rimraf(`${cwd}/build`); diff --git a/packages/kit/src/runtime/client/renderer.js b/packages/kit/src/runtime/client/renderer.js index 1d4ba6ec7a1d..1726d47a068b 100644 --- a/packages/kit/src/runtime/client/renderer.js +++ b/packages/kit/src/runtime/client/renderer.js @@ -195,11 +195,12 @@ export class Renderer { * status: number; * error: Error; * nodes: Array>; - * url: URL; * params: Record; * }} selected */ - async start({ status, error, nodes, url, params }) { + async start({ status, error, nodes, params }) { + const url = new URL(location.href); + /** @type {Array} */ const branch = []; @@ -211,9 +212,6 @@ export class Renderer { let error_args; - // url.hash is empty when coming from the server - url.hash = window.location.hash; - try { for (let i = 0; i < nodes.length; i += 1) { const is_leaf = i === nodes.length - 1; diff --git a/packages/kit/src/runtime/client/start.js b/packages/kit/src/runtime/client/start.js index 61019a594ee0..af8320bc1c0c 100644 --- a/packages/kit/src/runtime/client/start.js +++ b/packages/kit/src/runtime/client/start.js @@ -21,7 +21,6 @@ import { set_paths } from '../paths.js'; * status: number; * error: Error; * nodes: Array>; - * url: URL; * params: Record; * }; * }} opts diff --git a/packages/kit/src/runtime/server/page/render.js b/packages/kit/src/runtime/server/page/render.js index 38fdecd11ba5..cc50655c5a71 100644 --- a/packages/kit/src/runtime/server/page/render.js +++ b/packages/kit/src/runtime/server/page/render.js @@ -177,7 +177,6 @@ export async function render_response({ .map(({ node }) => `import(${s(options.prefix + node.entry)})`) .join(',\n\t\t\t\t\t\t')} ], - url: new URL(${s(url.href)}), params: ${devalue(params)} }` : 'null'} }); diff --git a/packages/kit/test/prerendering/options/test/test.js b/packages/kit/test/prerendering/options/test/test.js index 7d08e436ad69..d38c68002250 100644 --- a/packages/kit/test/prerendering/options/test/test.js +++ b/packages/kit/test/prerendering/options/test/test.js @@ -11,13 +11,11 @@ const read = (file) => fs.readFileSync(`${build}/${file}`, 'utf-8'); test('prerenders /path-base', () => { const content = read('index.html'); assert.ok(content.includes('

hello

')); - assert.ok(content.includes('http://sveltekit-prerender/path-base')); }); test('prerenders nested /path-base', () => { const content = read('nested/index.html'); assert.ok(content.includes('

nested hello

')); - assert.ok(content.includes('http://sveltekit-prerender/path-base/nested')); }); test('adds CSP headers via meta tag', () => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 967ce27570d0..b591e14e686f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -143,6 +143,7 @@ importers: packages/adapter-static: specifiers: '@sveltejs/kit': workspace:* + devalue: ^2.0.1 playwright-chromium: ^1.17.0 port-authority: ^1.1.2 sirv: ^2.0.0 @@ -153,6 +154,7 @@ importers: tiny-glob: 0.2.9 devDependencies: '@sveltejs/kit': link:../kit + devalue: 2.0.1 playwright-chromium: 1.17.0 port-authority: 1.1.2 sirv: 2.0.0