docs: use per-hook headings on the hooks page#16396
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/201faccdf3646f0def063e60a66338305ade8ebcOpen in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
|
| The following hooks can be added to `src/hooks.server.js`: | ||
|
|
||
| ### handle | ||
| > [!NOTE] Declared in `src/hooks.server.js` |
There was a problem hiding this comment.
| > [!NOTE] Declared in `src/hooks.server.js` | |
| > [!NOTE] Can be added to `src/hooks.server.js` |
| Note that `resolve(...)` will never throw an error, it will always return a `Promise<Response>` with the appropriate status code. If an error is thrown elsewhere during `handle`, it is treated as fatal, and SvelteKit will respond with a JSON representation of the error or a fallback error page — which can be customised via `src/error.html` — depending on the `Accept` header. You can read more about error handling [here](errors). | ||
|
|
||
| ### handleFetch | ||
| > [!NOTE] Declared in `src/hooks.server.js` |
There was a problem hiding this comment.
| > [!NOTE] Declared in `src/hooks.server.js` | |
| > [!NOTE] Can be added to `src/hooks.server.js` |
| ### handleValidationError | ||
| ## handleValidationError | ||
|
|
||
| > [!NOTE] Declared in `src/hooks.server.js` |
There was a problem hiding this comment.
| > [!NOTE] Declared in `src/hooks.server.js` | |
| > [!NOTE] Can be added to `src/hooks.server.js` |
| ## handleError | ||
|
|
||
| ### handleError | ||
| > [!NOTE] Declared in `src/hooks.server.js` and `src/hooks.client.js` |
There was a problem hiding this comment.
| > [!NOTE] Declared in `src/hooks.server.js` and `src/hooks.client.js` | |
| > [!NOTE] Can be added to `src/hooks.server.js` and `src/hooks.client.js` |
| ### init | ||
| ## init | ||
|
|
||
| > [!NOTE] Declared in `src/hooks.server.js` and `src/hooks.client.js` |
There was a problem hiding this comment.
| > [!NOTE] Declared in `src/hooks.server.js` and `src/hooks.client.js` | |
| > [!NOTE] Can be add to `src/hooks.server.js` and `src/hooks.client.js` |
| ## reroute | ||
|
|
||
| ### reroute | ||
| > [!NOTE] Declared in `src/hooks.js`, and runs on both server and client |
There was a problem hiding this comment.
| > [!NOTE] Declared in `src/hooks.js`, and runs on both server and client | |
| > [!NOTE] Can be added to `src/hooks.js`; it runs on both server and client |
| ### transport | ||
| ## transport | ||
|
|
||
| > [!NOTE] Declared in `src/hooks.js`, and runs on both server and client |
There was a problem hiding this comment.
| > [!NOTE] Declared in `src/hooks.js`, and runs on both server and client | |
| > [!NOTE] Can be added to `src/hooks.js`; it runs on both server and client |
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
closes #14896 The `router.resolution` docs say the server "has an opportunity to intercept each navigation (for example through a middleware)". #14896 read that as "the `handle` hook runs", which it does not. Route resolution requests are answered as soon as the route has been looked up ([respond.js#L323-L324](https://github.com/sveltejs/kit/blob/1406668dbc9c18928dabeff9d15ec756d6d455b3/packages/kit/src/runtime/server/respond.js#L323-L324)), before `handle` is invoked and after `reroute` has run ([respond.js#L249](https://github.com/sveltejs/kit/blob/1406668dbc9c18928dabeff9d15ec756d6d455b3/packages/kit/src/runtime/server/respond.js#L249)). Verified empirically in dev and in preview after a production build, details in #14896 (comment). The wording dates to #13379, which introduced server-side route resolution. The new sentence is scoped to the route lookup rather than stating a blanket "handle never runs", because there is one path where it does. A pathname that fails to decode falls through to normal request handling ([respond.js#L272-L277](https://github.com/sveltejs/kit/blob/1406668dbc9c18928dabeff9d15ec756d6d455b3/packages/kit/src/runtime/server/respond.js#L272-L277)), deliberate behavior from #15744 so that malformed URLs render the default error page. In production `GET /%c0/__route.js` therefore reaches `handle` with pathname `/%c0` before being rejected with a 400. Dev masks this because the dev middleware rejects malformed URIs earlier, which #15744 also notes. Two changes to the option's JSDoc. "Middleware" now says what it refers to, and a sentence states which hooks run for resolution requests. `types/index.d.ts` regenerated. Note on sequencing, #16396 also touches `public.d.ts` (different lines) and regenerates `types/index.d.ts`; whichever merges second needs a trivial rebase and regeneration. --- ### Please don't delete this checklist! Before submitting the PR, please make sure you do the following: - [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs - [x] This message body should clearly illustrate what problems it solves. - [x] Ideally, include a test that fails without this PR but passes with it. ### Tests - [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` and `pnpm check` ### Changesets - [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running `pnpm changeset` and following the prompts. Changesets that add features should be `minor` and those that fix bugs should be `patch`. Please prefix changeset messages with `feat:`, `fix:`, or `chore:`. ### Edits - [x] Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed. --------- Co-authored-by: Nic Polumeyv <nicolas.polum@gmail.com>
follow-up to #16396, which unfortunately broke the docs as a result of how they're being built during the 2-3 transition. We need to apply the same changes to `main`, and then merge sveltejs/svelte.dev#2102 --------- Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com> Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
closes #16337
Implements the docs half of #16337, per #16337 (comment). The 'Server hooks', 'Shared hooks' and 'Universal hooks' headings are gone. Each hook is now its own h2 with a note under it saying where it is declared, following the sketch in the issue body. Since the file rename was declined, the notes for
rerouteandtransportsaysrc/hooks.jsrather than the sketchedhooks.shared.ts.A few decisions worth reviewing.
localsis not a hook but keeps its own heading. Links tohooks#Server-hooks-localsexist today, and folding the section intohandlewould bury it.sequenceand the second parameter ofresolvecurrently sit inside thelocalssection. They were part of thehandlesection until docs: auth guide #12810 inserted the### localsheading above them for the auth guide to link to, so moving them back intohandlerestores the original placement. Cut and paste, no rewording.hooks#Server-hooks-handlebecomeshooks#handleand so on. All references in the docs tree and the JSDoc are updated, including two runtime error messages that embed docs URLs, the test asserting one of them, and the regeneratedpackages/kit/types/index.d.ts.Server-hookscategory heading itself. Thehooks.server.jsfile link in server-only-modules now points at the top of the hooks page, and the two "server hooks" prose links in the auth and web-standards pages point athandle, which is the hook they describe.hooks#Server-hooks-handleURL in the language-tools TypeScript plugin and some old blog posts on svelte.dev. Happy to send the language-tools follow-up once this merges, and to add redirects if the site has a mechanism for them.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits