diff --git a/.changeset/bright-lizards-deny.md b/.changeset/bright-lizards-deny.md new file mode 100644 index 0000000000000..59c886b284d20 --- /dev/null +++ b/.changeset/bright-lizards-deny.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': minor +--- + +feat: richer error message for invalid exports diff --git a/.changeset/seven-teachers-tell.md b/.changeset/seven-teachers-tell.md new file mode 100644 index 0000000000000..29c1a75dbd573 --- /dev/null +++ b/.changeset/seven-teachers-tell.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +chore: throw more helpful error when encoding uri fails during prerendering diff --git a/.changeset/smooth-shrimps-look.md b/.changeset/smooth-shrimps-look.md deleted file mode 100644 index a1a20c322cbdb..0000000000000 --- a/.changeset/smooth-shrimps-look.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@sveltejs/kit': patch ---- - -fix: always default `paths.assets` to `paths.base` diff --git a/documentation/docs/20-core-concepts/10-routing.md b/documentation/docs/20-core-concepts/10-routing.md index 7f1f89906b488..b6026c1b45b68 100644 --- a/documentation/docs/20-core-concepts/10-routing.md +++ b/documentation/docs/20-core-concepts/10-routing.md @@ -248,7 +248,7 @@ Like `+layout.js`, `+layout.server.js` can export [page options](page-options) ## +server -As well as pages, you can define routes with a `+server.js` file (sometimes referred to as an 'API route' or an 'endpoint'), which gives you full control over the response. Your `+server.js` file (or `+server.ts`) exports functions corresponding to HTTP verbs like `GET`, `POST`, `PATCH`, `PUT` and `DELETE` that take a `RequestEvent` argument and return a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object. +As well as pages, you can define routes with a `+server.js` file (sometimes referred to as an 'API route' or an 'endpoint'), which gives you full control over the response. Your `+server.js` file (or `+server.ts`) exports functions corresponding to HTTP verbs like `GET`, `POST`, `PATCH`, `PUT`, `DELETE`, and `OPTIONS` that take a `RequestEvent` argument and return a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object. For example we could create an `/api/random-number` route with a `GET` handler: @@ -279,9 +279,11 @@ You can use the [`error`](modules#sveltejs-kit-error), [`redirect`](modules#svel If an error is thrown (either `throw error(...)` or an unexpected error), the response will be a JSON representation of the error or a fallback error page — which can be customised via `src/error.html` — depending on the `Accept` header. The [`+error.svelte`](#error) component will _not_ be rendered in this case. You can read more about error handling [here](errors). +> When creating an `OPTIONS` handler, note that Vite will inject `Access-Control-Allow-Origin` and `Access-Control-Allow-Methods` headers — these will not be present in production unless you add them. + ### Receiving data -By exporting `POST`/`PUT`/`PATCH`/`DELETE` handlers, `+server.js` files can be used to create a complete API: +By exporting `POST`/`PUT`/`PATCH`/`DELETE`/`OPTIONS` handlers, `+server.js` files can be used to create a complete API: ```svelte /// file: src/routes/add/+page.svelte @@ -327,7 +329,7 @@ export async function POST({ request }) { `+server.js` files can be placed in the same directory as `+page` files, allowing the same route to be either a page or an API endpoint. To determine which, SvelteKit applies the following rules: -- `PUT`/`PATCH`/`DELETE` requests are always handled by `+server.js` since they do not apply to pages +- `PUT`/`PATCH`/`DELETE`/`OPTIONS` requests are always handled by `+server.js` since they do not apply to pages - `GET`/`POST` requests are treated as page requests if the `accept` header prioritises `text/html` (in other words, it's a browser page request), else they are handled by `+server.js` ## $types diff --git a/documentation/docs/20-core-concepts/20-load.md b/documentation/docs/20-core-concepts/20-load.md index 4a563afc9002a..967218babeed3 100644 --- a/documentation/docs/20-core-concepts/20-load.md +++ b/documentation/docs/20-core-concepts/20-load.md @@ -416,7 +416,7 @@ export function load({ locals }) { } ``` -> Make sure you're not catching the thrown redirect, which results in a noop. +> Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it. In the browser, you can also navigate programmatically outside of a `load` function using [`goto`](modules#$app-navigation-goto) from [`$app.navigation`](modules#$app-navigation). diff --git a/documentation/docs/25-build-and-deploy/40-adapter-node.md b/documentation/docs/25-build-and-deploy/40-adapter-node.md index 2cc9c182be777..ca370579e99e3 100644 --- a/documentation/docs/25-build-and-deploy/40-adapter-node.md +++ b/documentation/docs/25-build-and-deploy/40-adapter-node.md @@ -122,7 +122,8 @@ export default { // default options are shown out: 'build', precompress: false, - envPrefix: '' + envPrefix: '', + polyfill: true }) } }; @@ -140,6 +141,10 @@ Enables precompressing using gzip and brotli for assets and prerendered pages. I If you need to change the name of the environment variables used to configure the deployment (for example, to deconflict with environment variables you don't control), you can specify a prefix: +### polyfill + +Controlls whether your build will load polyfills for missing modules. It defaults to `true`, and should only be disabled when using Node 18.11 or greater. + ```js envPrefix: 'MY_CUSTOM_'; ``` diff --git a/documentation/docs/30-advanced/40-service-workers.md b/documentation/docs/30-advanced/40-service-workers.md index 09c1b8a8fb0e3..92da584e51843 100644 --- a/documentation/docs/30-advanced/40-service-workers.md +++ b/documentation/docs/30-advanced/40-service-workers.md @@ -24,6 +24,7 @@ The following example caches the built app and any files in `static` eagerly, an ```js // @errors: 2339 +/// import { build, files, version } from '$service-worker'; // Create a unique cache name for this deployment @@ -108,6 +109,7 @@ navigator.serviceWorker.register('/service-worker.js', { Setting up proper types for service workers requires some manual setup. Inside your `service-worker.js`, add the following to the top of your file: ```original-js +/// /// /// /// @@ -115,6 +117,7 @@ Setting up proper types for service workers requires some manual setup. Inside y const sw = /** @type {ServiceWorkerGlobalScope} */ (/** @type {unknown} */ (self)); ``` ```generated-ts +/// /// /// /// @@ -122,7 +125,7 @@ const sw = /** @type {ServiceWorkerGlobalScope} */ (/** @type {unknown} */ (self const sw = self as unknown as ServiceWorkerGlobalScope; ``` -This disables access to DOM typings like `HTMLElement` which are not available inside a service worker and instantiates the correct globals. The reassignment of `self` to `sw` allows you to type cast it in the process (there are a couple of ways to do this, but the easiest that requires no additional files). Use `sw` instead of `self` in the rest of the file. +This disables access to DOM typings like `HTMLElement` which are not available inside a service worker and instantiates the correct globals. The reassignment of `self` to `sw` allows you to type cast it in the process (there are a couple of ways to do this, but the easiest that requires no additional files). Use `sw` instead of `self` in the rest of the file. The reference to the SvelteKit types ensures that the `$service-worker` import has proper type definitions. ## Other solutions diff --git a/documentation/docs/30-advanced/65-snapshots.md b/documentation/docs/30-advanced/65-snapshots.md index 41971b98e9416..fff0a2e372a0e 100644 --- a/documentation/docs/30-advanced/65-snapshots.md +++ b/documentation/docs/30-advanced/65-snapshots.md @@ -21,7 +21,8 @@ To do this, export a `snapshot` object with `capture` and `restore` methods from
-