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 ffaf2be57dac..0d5daee86bfe 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -671,14 +671,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/client/client.js b/packages/kit/src/runtime/client/client.js index b2ef3150a354..91fa38c7db5d 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/src/runtime/client/utils.js b/packages/kit/src/runtime/client/utils.js index 5bfe038747ce..bf723c554073 100644 --- a/packages/kit/src/runtime/client/utils.js +++ b/packages/kit/src/runtime/client/utils.js @@ -1,6 +1,6 @@ import { BROWSER, DEV } from 'esm-env'; import { writable } from 'svelte/store'; -import { assets } from '$app/paths'; +import { assets } from '$app/paths/internal/client'; import { version } from '__sveltekit/environment'; import { PRELOAD_PRIORITIES } from './constants.js'; diff --git a/packages/kit/test/apps/basics/src/routes/paths/+page.svelte b/packages/kit/test/apps/basics/src/routes/paths/+page.svelte deleted file mode 100644 index 73d1cb7eb4ef..000000000000 --- a/packages/kit/test/apps/basics/src/routes/paths/+page.svelte +++ /dev/null @@ -1,5 +0,0 @@ - - -
{JSON.stringify({ base, assets })}
diff --git a/packages/kit/test/apps/basics/src/routes/paths/deeply/nested/+page.svelte b/packages/kit/test/apps/basics/src/routes/paths/deeply/nested/+page.svelte deleted file mode 100644 index 73d1cb7eb4ef..000000000000 --- a/packages/kit/test/apps/basics/src/routes/paths/deeply/nested/+page.svelte +++ /dev/null @@ -1,5 +0,0 @@ - - -
{JSON.stringify({ base, assets })}
diff --git a/packages/kit/test/apps/basics/test/test.js b/packages/kit/test/apps/basics/test/test.js index 768a69f8039d..124e80119575 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('/'); 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