From 198a8d852e4bc765c37252e71a326e0b4007ac87 Mon Sep 17 00:00:00 2001 From: Tee Ming Date: Sat, 7 Mar 2026 21:33:18 +0800 Subject: [PATCH 1/5] remove base assets and resolveRoute --- .changeset/easy-weeks-tan.md | 5 + .../docs/98-reference/20-$app-paths.md | 3 + packages/kit/src/core/postbuild/prerender.js | 2 +- packages/kit/src/exports/public.d.ts | 4 +- packages/kit/src/runtime/app/paths/client.js | 2 - .../kit/src/runtime/app/paths/public.d.ts | 28 ---- packages/kit/src/runtime/app/paths/server.js | 2 - packages/kit/src/runtime/app/server/index.js | 2 +- packages/kit/src/runtime/client/client.js | 2 +- packages/kit/test/apps/basics/test/test.js | 145 ------------------ .../apps/options-2/src/routes/+page.svelte | 8 +- .../routes/deeply/nested/page/+page.svelte | 6 +- .../routes/trailing-slash-server/+page.svelte | 6 +- packages/kit/test/apps/options-2/test/test.js | 10 +- .../apps/options/source/pages/base/+page.js | 6 +- .../options/source/pages/match/+server.js | 7 +- .../source/pages/resolve-route/+page.svelte | 7 - .../pages/resolve-route/[foo]/+page.svelte | 5 - .../options/source/pages/slash/+page.svelte | 4 +- .../apps/options/test/paths-assets.test.js | 13 +- packages/kit/test/apps/options/test/test.js | 27 ++-- .../paths-base/src/routes/redirect/+page.js | 4 +- 22 files changed, 60 insertions(+), 238 deletions(-) create mode 100644 .changeset/easy-weeks-tan.md delete mode 100644 packages/kit/test/apps/options/source/pages/resolve-route/+page.svelte delete mode 100644 packages/kit/test/apps/options/source/pages/resolve-route/[foo]/+page.svelte diff --git a/.changeset/easy-weeks-tan.md b/.changeset/easy-weeks-tan.md new file mode 100644 index 000000000000..8bfab1133b4b --- /dev/null +++ b/.changeset/easy-weeks-tan.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': major +--- + +breaking: remove `base`, `assets`, and `resolveRoute` from `$app/paths` diff --git a/documentation/docs/98-reference/20-$app-paths.md b/documentation/docs/98-reference/20-$app-paths.md index 32a350965e4a..b5a1cb781b68 100644 --- a/documentation/docs/98-reference/20-$app-paths.md +++ b/documentation/docs/98-reference/20-$app-paths.md @@ -3,3 +3,6 @@ title: $app/paths --- > MODULE: $app/paths + +> [!LEGACY] +> `base`, `assets`, and `resolveRoute` were removed in 3.0 diff --git a/packages/kit/src/core/postbuild/prerender.js b/packages/kit/src/core/postbuild/prerender.js index f8d8603bdb32..f0e3fca67d0b 100644 --- a/packages/kit/src/core/postbuild/prerender.js +++ b/packages/kit/src/core/postbuild/prerender.js @@ -134,7 +134,7 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env, roo ({ status, path, referrer, referenceType }) => { const message = status === 404 && !path.startsWith(config.paths.base) - ? `${path} does not begin with \`base\`, which is configured in \`paths.base\` and can be imported from \`$app/paths\` - see https://svelte.dev/docs/kit/configuration#paths for more info` + ? `${path} does not begin with \`base\`. You can fix this by using \`resolve('${path}')\` from \`$app/paths\`. The base path is configurable from \`paths.base\` - see https://svelte.dev/docs/kit/configuration#paths for more info` : path; return `${status} ${message}${referrer ? ` (${referenceType} from ${referrer})` : ''}`; diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index 2f3b95808cab..d9fae8d58552 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -663,14 +663,14 @@ export interface KitConfig { */ assets?: '' | `http://${string}` | `https://${string}`; /** - * A root-relative path that must start, but not end with `/` (e.g. `/base-path`), unless it is the empty string. This specifies where your app is served from and allows the app to live on a non-root path. Note that you need to prepend all your root-relative links with the base value or they will point to the root of your domain, not your `base` (this is how the browser works). You can use [`base` from `$app/paths`](https://svelte.dev/docs/kit/$app-paths#base) for that: `Link`. If you find yourself writing this often, it may make sense to extract this into a reusable component. + * A root-relative path that must start, but not end with `/` (e.g. `/base-path`), unless it is the empty string. This specifies where your app is served from and allows the app to live on a non-root path. Note that you need to prepend all your root-relative links with the base value or they will point to the root of your domain, not your `base` (this is how the browser works). You can use [`resolve(...)` from `$app/paths`](https://svelte.dev/docs/kit/$app-paths#resolve) for that: `Link`. If you find yourself writing this often, it may make sense to extract this into a reusable component. * @default "" */ base?: '' | `/${string}`; /** * Whether to use relative asset paths. * - * If `true`, `base` and `assets` imported from `$app/paths` will be replaced with relative asset paths during server-side rendering, resulting in more portable HTML. + * If `true`, paths created with `resolve()` and `asset()` imported from `$app/paths` will be replaced with relative asset paths during server-side rendering, resulting in more portable HTML. * If `false`, `%sveltekit.assets%` and references to build artifacts will always be root-relative paths, unless `paths.assets` is an external URL * * [Single-page app](https://svelte.dev/docs/kit/single-page-apps) fallback pages will always use absolute paths, regardless of this setting. diff --git a/packages/kit/src/runtime/app/paths/client.js b/packages/kit/src/runtime/app/paths/client.js index ec64dee44646..fb155aaf3b5a 100644 --- a/packages/kit/src/runtime/app/paths/client.js +++ b/packages/kit/src/runtime/app/paths/client.js @@ -95,5 +95,3 @@ export async function match(url) { return null; } - -export { base, assets, resolve as resolveRoute }; diff --git a/packages/kit/src/runtime/app/paths/public.d.ts b/packages/kit/src/runtime/app/paths/public.d.ts index 600a10317234..878560588121 100644 --- a/packages/kit/src/runtime/app/paths/public.d.ts +++ b/packages/kit/src/runtime/app/paths/public.d.ts @@ -1,29 +1 @@ -import { RouteIdWithSearchOrHash, PathnameWithSearchOrHash, ResolvedPathname } from '$app/types'; -import { ResolveArgs } from './types.js'; - export { resolve, asset, match } from './client.js'; - -/** - * A string that matches [`config.kit.paths.base`](https://svelte.dev/docs/kit/configuration#paths). - * - * Example usage: `Link` - * - * @deprecated Use [`resolve(...)`](https://svelte.dev/docs/kit/$app-paths#resolve) instead - */ -export let base: '' | `/${string}`; - -/** - * An absolute path that matches [`config.kit.paths.assets`](https://svelte.dev/docs/kit/configuration#paths). - * - * > [!NOTE] If a value for `config.kit.paths.assets` is specified, it will be replaced with `'/_svelte_kit_assets'` during `vite dev` or `vite preview`, since the assets don't yet live at their eventual URL. - * - * @deprecated Use [`asset(...)`](https://svelte.dev/docs/kit/$app-paths#asset) instead - */ -export let assets: '' | `https://${string}` | `http://${string}` | '/_svelte_kit_assets'; - -/** - * @deprecated Use [`resolve(...)`](https://svelte.dev/docs/kit/$app-paths#resolve) instead - */ -export function resolveRoute( - ...args: ResolveArgs -): ResolvedPathname; diff --git a/packages/kit/src/runtime/app/paths/server.js b/packages/kit/src/runtime/app/paths/server.js index 2338f4b53f9d..906035b900d0 100644 --- a/packages/kit/src/runtime/app/paths/server.js +++ b/packages/kit/src/runtime/app/paths/server.js @@ -67,5 +67,3 @@ export async function match(url) { return null; } - -export { base, assets, resolve as resolveRoute }; diff --git a/packages/kit/src/runtime/app/server/index.js b/packages/kit/src/runtime/app/server/index.js index 746278ec4890..8246d298cf1d 100644 --- a/packages/kit/src/runtime/app/server/index.js +++ b/packages/kit/src/runtime/app/server/index.js @@ -1,5 +1,5 @@ import { read_implementation, manifest } from '__sveltekit/server'; -import { base } from '$app/paths'; +import { base } from '$app/paths/internal/server'; import { DEV } from 'esm-env'; import { base64_decode } from '../../utils.js'; diff --git a/packages/kit/src/runtime/client/client.js b/packages/kit/src/runtime/client/client.js index 0faada3d4b01..e3ee7aa34f30 100644 --- a/packages/kit/src/runtime/client/client.js +++ b/packages/kit/src/runtime/client/client.js @@ -26,7 +26,7 @@ import { create_updated_store, load_css } from './utils.js'; -import { base } from '$app/paths'; +import { base } from '$app/paths/internal/client'; import * as devalue from 'devalue'; import { HISTORY_INDEX, diff --git a/packages/kit/test/apps/basics/test/test.js b/packages/kit/test/apps/basics/test/test.js index 768a69f8039d..476c79ee7c6a 100644 --- a/packages/kit/test/apps/basics/test/test.js +++ b/packages/kit/test/apps/basics/test/test.js @@ -730,22 +730,6 @@ test.describe('$app/environment', () => { }); test.describe('$app/paths', () => { - test('includes paths', async ({ page, javaScriptEnabled }) => { - test.skip( - process.env.SVELTE_ASYNC === 'true', - 'does not work with async, should use new functions instead' - ); - await page.goto('/paths'); - - let base = javaScriptEnabled ? '' : '.'; - expect(await page.innerHTML('pre')).toBe(JSON.stringify({ base, assets: base })); - - await page.goto('/paths/deeply/nested'); - - base = javaScriptEnabled ? '' : '../..'; - expect(await page.innerHTML('pre')).toBe(JSON.stringify({ base, assets: base })); - }); - // some browsers will re-request assets after a `pushState` // https://github.com/sveltejs/kit/issues/3748#issuecomment-1125980897 test('replaces %sveltekit.assets% in template with relative path, and makes it absolute in the client', async ({ @@ -753,10 +737,6 @@ test.describe('$app/paths', () => { page, javaScriptEnabled }) => { - test.skip( - process.env.SVELTE_ASYNC === 'true', - 'does not work with async, should use new functions instead' - ); const absolute = `${baseURL}/favicon.png`; await page.goto('/'); @@ -804,131 +784,6 @@ test.describe('$app/paths', () => { }); }); -// TODO SvelteKit 3: remove these tests -test.describe('$app/stores', () => { - test('can access page.url', async ({ baseURL, page }) => { - await page.goto('/origin'); - expect(await page.textContent('h1')).toBe(baseURL); - }); - - test('page store contains data', async ({ page, clicknav }) => { - await page.goto('/store/data/www'); - - const foo = { bar: 'Custom layout' }; - - expect(await page.textContent('#store-data')).toBe( - JSON.stringify({ foo, name: 'SvelteKit', value: 456, page: 'www' }) - ); - - await clicknav('a[href="/store/data/zzz"]'); - expect(await page.textContent('#store-data')).toBe( - JSON.stringify({ foo, name: 'SvelteKit', value: 456, page: 'zzz' }) - ); - - await clicknav('a[href="/store/data/xxx"]'); - expect(await page.textContent('#store-data')).toBe( - JSON.stringify({ foo, name: 'SvelteKit', value: 123 }) - ); - expect(await page.textContent('#store-error')).toBe('Params = xxx'); - - await clicknav('a[href="/store/data/yyy"]'); - expect(await page.textContent('#store-data')).toBe( - JSON.stringify({ foo, name: 'SvelteKit', value: 123 }) - ); - expect(await page.textContent('#store-error')).toBe('Params = yyy'); - }); - - test('should load data after reloading by goto', async ({ - page, - clicknav, - javaScriptEnabled - }) => { - await page.goto('/store/data/foo?reset=true'); - const stuff1 = { foo: { bar: 'Custom layout' }, name: 'SvelteKit', value: 123 }; - const stuff2 = { ...stuff1, foo: true, number: 2 }; - const stuff3 = { ...stuff2 }; - await page.goto('/store/data/www'); - - await clicknav('a[href="/store/data/foo"]'); - expect(JSON.parse((await page.textContent('#store-data')) ?? '')).toEqual(stuff1); - - await clicknav('#reload-button'); - expect(JSON.parse((await page.textContent('#store-data')) ?? '')).toEqual( - javaScriptEnabled ? stuff2 : stuff1 - ); - - await clicknav('a[href="/store/data/zzz"]'); - await clicknav('a[href="/store/data/foo"]'); - expect(JSON.parse((await page.textContent('#store-data')) ?? '')).toEqual(stuff3); - }); - - test('navigating store contains from, to and type', async ({ app, page, javaScriptEnabled }) => { - await page.goto('/store/navigating/a'); - - expect(await page.textContent('#nav-status')).toBe('not currently navigating'); - - if (javaScriptEnabled) { - await app.preloadCode('/store/navigating/b'); - - const res = await Promise.all([ - page.click('a[href="/store/navigating/b"]'), - page.textContent('#navigating') - ]); - - expect(res[1]).toBe('navigating from /store/navigating/a to /store/navigating/b (link)'); - - await page.waitForSelector('#not-navigating'); - expect(await page.textContent('#nav-status')).toBe('not currently navigating'); - - await Promise.all([ - expect(page.locator('#navigating')).toHaveText( - 'navigating from /store/navigating/b to /store/navigating/a (popstate)' - ), - page.goBack() - ]); - } - }); - - test('navigating store clears after aborted navigation', async ({ page, javaScriptEnabled }) => { - await page.goto('/store/navigating/a'); - - expect(await page.textContent('#nav-status')).toBe('not currently navigating'); - - if (javaScriptEnabled) { - await page.click('a[href="/store/navigating/c"]'); - await page.waitForTimeout(100); // gross, but necessary since no navigation occurs - await page.click('a[href="/store/navigating/a"]'); - - await page.waitForSelector('#not-navigating', { timeout: 5000 }); - expect(await page.textContent('#nav-status')).toBe('not currently navigating'); - } - }); - - test('should update page store when URL hash is changed through the address bar', async ({ - baseURL, - page, - javaScriptEnabled - }) => { - const href = `${baseURL}/store/data/zzz`; - await page.goto(href); - - expect(await page.textContent('#url-hash')).toBe(''); - - if (javaScriptEnabled) { - for (const urlHash of ['#1', '#2', '#5', '#8']) { - await page.evaluate( - ({ href, urlHash }) => { - location.href = `${href}${urlHash}`; - }, - { href, urlHash } - ); - - expect(await page.textContent('#url-hash')).toBe(urlHash); - } - } - }); -}); - test.describe('$app/state', () => { test('can access page.url', async ({ baseURL, page }) => { await page.goto('/origin'); diff --git a/packages/kit/test/apps/options-2/src/routes/+page.svelte b/packages/kit/test/apps/options-2/src/routes/+page.svelte index c026409d91ee..0a0db2251853 100644 --- a/packages/kit/test/apps/options-2/src/routes/+page.svelte +++ b/packages/kit/test/apps/options-2/src/routes/+page.svelte @@ -1,13 +1,13 @@

Hello

-

base: {base}

-

assets: {assets}

+

base: {resolve('/')}

+

assets: {asset('')}

-Go to /hello +Go to /hello