Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement #5748 #5778

Merged
merged 192 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from 119 commits
Commits
Show all changes
192 commits
Select commit Hold shift + click to select a range
47076c1
skeleton
dummdidumm Jul 29, 2022
5b49486
add moved info to files to be able to rewrite imports later
dummdidumm Jul 29, 2022
9f83032
add magic-string, start load extraction and manipulation logic
dummdidumm Jul 29, 2022
c10febb
Merge branch 'master' into migration-script
Rich-Harris Jul 31, 2022
5410a5b
Merge branch 'master' into migration-script
Rich-Harris Jul 31, 2022
ccb5059
move migration logic into new svelte-migrate package
Rich-Harris Jul 31, 2022
4387b2c
remove commented code
Rich-Harris Jul 31, 2022
08906cc
lockfile
Rich-Harris Jul 31, 2022
dd7fdd4
move components, extract load
Rich-Harris Jul 31, 2022
07ca11f
+page.server.js and +server.js
Rich-Harris Jul 31, 2022
836227b
remove unused code
Rich-Harris Jul 31, 2022
4c1334a
uncomment prompt
Rich-Harris Jul 31, 2022
2243175
add some errors
Rich-Harris Jul 31, 2022
f08c6cd
fix detection
Rich-Harris Jul 31, 2022
3a119b5
consistent casing
Rich-Harris Jul 31, 2022
f3a2d7c
not sure if typescript will ever fail to parse, but in any case its h…
Rich-Harris Jul 31, 2022
d9b988f
handle error with module context
Rich-Harris Aug 1, 2022
c3a2987
add some comments
Rich-Harris Aug 1, 2022
471dd17
update demo app
Rich-Harris Aug 1, 2022
84177d4
update skeleton app
Rich-Harris Aug 1, 2022
6640599
migrate kit.svelte.dev
Rich-Harris Aug 1, 2022
16b312c
fix dynamic import on windows, fix js/ts file ending, handle index.js…
dummdidumm Aug 1, 2022
02ab096
extract imports into Svelte migration task for QOL, don't adjust impo…
dummdidumm Aug 1, 2022
f85deee
Merge branch 'migration-script' into migrate-tests
dummdidumm Aug 1, 2022
1246ac3
migrate amp app
dummdidumm Aug 1, 2022
2d01f30
show message either way, could be other things gone wrong
dummdidumm Aug 1, 2022
27ee53c
Merge branch 'migration-script' into migrate-tests
dummdidumm Aug 1, 2022
4f88ead
windooows
dummdidumm Aug 1, 2022
3657ebd
Merge branch 'migration-script' into migrate-tests
dummdidumm Aug 1, 2022
8ccb1f9
more sophisticated auto migrations
dummdidumm Aug 1, 2022
e647683
Merge branch 'migration-script' into migrate-tests
dummdidumm Aug 1, 2022
b066076
migrate test/apps/basics
dummdidumm Aug 2, 2022
6c9489d
fix regex, dont show props message on error page, more sophisticated …
dummdidumm Aug 2, 2022
d69ea50
pretend to make this more readable
dummdidumm Aug 2, 2022
cc32bd1
Merge branch 'migration-script' into migrate-tests
dummdidumm Aug 2, 2022
305caee
adjust import location for error and redirect
dummdidumm Aug 2, 2022
740bcdc
Merge branch 'migration-script' into migrate-tests
dummdidumm Aug 2, 2022
cbd67cb
update tests
dummdidumm Aug 2, 2022
9ad6691
only show short automigration message on success, only migrate where …
dummdidumm Aug 2, 2022
88b46ea
Merge branch 'migration-script' into migrate-tests
dummdidumm Aug 2, 2022
5e37428
shorten redirect/error if no second argument given
dummdidumm Aug 2, 2022
d9da6f7
Merge branch 'migration-script' into migrate-tests
dummdidumm Aug 2, 2022
de773cc
use git mv if available
dummdidumm Aug 2, 2022
ac90010
Merge branch 'migration-script' into migrate-tests
dummdidumm Aug 2, 2022
eca83af
merge master
Rich-Harris Aug 4, 2022
5500e3e
update options tests
Rich-Harris Aug 4, 2022
b90be49
update options-2 tests
Rich-Harris Aug 4, 2022
d406f13
update writes tests
Rich-Harris Aug 4, 2022
624b77f
Merge branch 'master' into migrate-tests
Rich-Harris Aug 4, 2022
62300fa
migrate (most) prerendering/basics tests
Rich-Harris Aug 4, 2022
9b09310
migrate more tests
Rich-Harris Aug 4, 2022
2a3195c
update adapter-static tests
Rich-Harris Aug 4, 2022
31b686c
it begins (#5782)
Rich-Harris Aug 8, 2022
82d858a
merge master
Rich-Harris Aug 8, 2022
d278c22
Docs for the new API (#5810)
dummdidumm Aug 8, 2022
e345d3f
enable all tests
Rich-Harris Aug 8, 2022
f9b2f75
Unbundling (#5853)
Rich-Harris Aug 8, 2022
26649f3
format
Rich-Harris Aug 8, 2022
fdcf7d8
replace some TODOs
Rich-Harris Aug 8, 2022
e2acd9d
only add param tag if param exists
Rich-Harris Aug 8, 2022
fde7fd0
fix some type stuff
Rich-Harris Aug 8, 2022
0cc87d3
fix some type stuff
Rich-Harris Aug 8, 2022
b57a83e
more type fixes
Rich-Harris Aug 8, 2022
3db17b0
reuse load_data
Rich-Harris Aug 8, 2022
8d32846
fix imports. damn you vscode, you dont have to be like this
Rich-Harris Aug 8, 2022
745ce43
fix some stuff
Rich-Harris Aug 8, 2022
d62d041
remove unused import
Rich-Harris Aug 9, 2022
4142daa
fix prefetchRoutes
Rich-Harris Aug 9, 2022
85d9998
fix a handful more tests
Rich-Harris Aug 9, 2022
641107a
comment out likely obsolete setHeaders in test
dummdidumm Aug 9, 2022
f8bb1c1
fix write_client_manifest
dummdidumm Aug 9, 2022
868d2f4
fix off-by-one error for client error page rendering
dummdidumm Aug 9, 2022
5b23201
update page store when only data changed
dummdidumm Aug 9, 2022
d2790a6
handle page endpoint without get
dummdidumm Aug 9, 2022
437f163
reenable tests
dummdidumm Aug 9, 2022
129c460
fix windows/vite path issue
dummdidumm Aug 9, 2022
1c052b0
pass serialized server data to client
dummdidumm Aug 9, 2022
263fd53
fix uses tracking for page endpoints in client
dummdidumm Aug 9, 2022
6625a82
unfix the buggy drive letter fix
dummdidumm Aug 9, 2022
b5c6dad
set headers/etag for page endpoints
dummdidumm Aug 9, 2022
03b8205
add HttpError identifier to serialized version and make connection vi…
dummdidumm Aug 10, 2022
4edfb32
call handle_error in json request
dummdidumm Aug 10, 2022
e709d3f
fix test
dummdidumm Aug 10, 2022
f781756
omit json-data when ssr but no hydration
dummdidumm Aug 10, 2022
4d8e64e
remove obsolete caching logic from client, adjust test
dummdidumm Aug 10, 2022
9f535b1
add migration link
dummdidumm Aug 10, 2022
d969dbc
make typescript non-required again by lazy-loading it, fix package.files
dummdidumm Aug 10, 2022
331a7ca
only create proxy if something was modified
dummdidumm Aug 10, 2022
89ed6f6
update pnpm lock
dummdidumm Aug 10, 2022
aeb21a4
always bundle @sveltejs/kit
Rich-Harris Aug 10, 2022
502456c
fix some write_types stuff
Rich-Harris Aug 10, 2022
2c290bb
this took waaaay too long to figure out
Rich-Harris Aug 10, 2022
aeb2fcb
prettier
Rich-Harris Aug 10, 2022
4617a53
fix a bunch of typescript stuff
Rich-Harris Aug 10, 2022
6ee351a
shrug
Rich-Harris Aug 10, 2022
31195f3
probably no point generating types if no ts?
Rich-Harris Aug 11, 2022
253efcf
refactor write_types to support addition of layout types
Rich-Harris Aug 11, 2022
a2b7f90
rename Data to PageData and LayoutData
Rich-Harris Aug 11, 2022
0321525
fix manifest generation with named layouts
Rich-Harris Aug 11, 2022
f632c35
update tests
Rich-Harris Aug 11, 2022
4f9ef19
generate LayoutLoad and LayoutData types
Rich-Harris Aug 11, 2022
c185017
windows fix, deduplicate, use AwaitedProperties
dummdidumm Aug 11, 2022
f79fb3b
write Errors type
dummdidumm Aug 11, 2022
11774a9
fix AwaitedProperties type, add AwaitedErrors type
dummdidumm Aug 11, 2022
d0ea483
fix test
dummdidumm Aug 11, 2022
ef6dd1b
fix test
dummdidumm Aug 11, 2022
d8fc3d4
trying an env fix, not sure if that works on linux
dummdidumm Aug 11, 2022
a89eee3
mhm
dummdidumm Aug 11, 2022
102b093
temporary run only env test on CI
dummdidumm Aug 11, 2022
9348d92
fix type reference in create-svelte
dummdidumm Aug 11, 2022
5af956c
getting desperate
dummdidumm Aug 11, 2022
2de6338
even more scoped test execution
dummdidumm Aug 11, 2022
4f8d206
check why posixify doesnt work
dummdidumm Aug 11, 2022
2702a79
Data -> PageData
Rich-Harris Aug 11, 2022
42e2ceb
merge
Rich-Harris Aug 11, 2022
401a3ca
wtf, does this work now or not?
dummdidumm Aug 11, 2022
f07f039
remove unnecessary migration warnings, add error for props -> data
Rich-Harris Aug 11, 2022
64f50f4
Merge branch 'migrate-tests' of github.com:sveltejs/kit into migrate-…
Rich-Harris Aug 11, 2022
1f91c43
omg works, reenable all tests
dummdidumm Aug 11, 2022
f7e5e43
some docs progress
Rich-Harris Aug 11, 2022
7c5181f
Merge branch 'migrate-tests' of github.com:sveltejs/kit into migrate-…
Rich-Harris Aug 11, 2022
df6aa26
fix file ending issue in write_types
dummdidumm Aug 11, 2022
cb88d56
fix path resolution in write_types
dummdidumm Aug 11, 2022
17db555
fix type error in generated d.ts file
dummdidumm Aug 11, 2022
e51ce3b
updates
Rich-Harris Aug 11, 2022
6226c92
ooh it works
Rich-Harris Aug 11, 2022
1a95ee4
Merge branch 'migrate-tests' of github.com:sveltejs/kit into migrate-…
Rich-Harris Aug 11, 2022
b3c9875
sprinkle some types
Rich-Harris Aug 11, 2022
590cdbd
add checkJs
Rich-Harris Aug 11, 2022
5ba0761
get some pages building
Rich-Harris Aug 11, 2022
16b09a4
.ts -> .js
Rich-Harris Aug 11, 2022
b42a1a1
simplify write_types
Rich-Harris Aug 11, 2022
c1fb616
more docs types stuff
Rich-Harris Aug 11, 2022
350aab8
rename node.module to node.shared, which is more descriptive
Rich-Harris Aug 11, 2022
5479864
rename route.page to route.leaf
Rich-Harris Aug 11, 2022
b9f8be6
return all route data with __data.json, not just the leaf
Rich-Harris Aug 11, 2022
1ad7a75
load all server data in one go on the client. this should probably ha…
Rich-Harris Aug 11, 2022
f4e3e09
update types on file edit
dummdidumm Aug 12, 2022
daca0bc
only write types that have changed
dummdidumm Aug 12, 2022
77fa27e
debounce updates to manifest
dummdidumm Aug 12, 2022
330960e
add parent data type inference. introduce a breaking change to the Lo…
dummdidumm Aug 12, 2022
3881094
rename/tidy up some stuff
Rich-Harris Aug 12, 2022
f4b4fca
fix
Rich-Harris Aug 12, 2022
a110a52
fix some stuff
Rich-Harris Aug 12, 2022
ef03838
set cookies on __data.json requests
Rich-Harris Aug 12, 2022
7d3921c
fix some stuff
Rich-Harris Aug 12, 2022
bf87bb7
only load data from server if we have some
Rich-Harris Aug 12, 2022
be5f47f
remove obsolete todo
Rich-Harris Aug 12, 2022
1d42f05
update test
Rich-Harris Aug 12, 2022
18fe83e
lint
Rich-Harris Aug 12, 2022
5842b76
fix prerendered __data.json
Rich-Harris Aug 12, 2022
b78a879
add json helper
Rich-Harris Aug 13, 2022
719929a
use json helper in migration
Rich-Harris Aug 13, 2022
831b8f6
fixes
Rich-Harris Aug 13, 2022
dc92d20
center routing documentation on + files
Rich-Harris Aug 13, 2022
76e101d
get docs building again
Rich-Harris Aug 14, 2022
ec30024
update example
Rich-Harris Aug 14, 2022
79b9565
tidy up
Rich-Harris Aug 15, 2022
da7659c
update load docs
Rich-Harris Aug 15, 2022
5c93626
document promise unwrapping
Rich-Harris Aug 15, 2022
41f8f8f
typo
Rich-Harris Aug 15, 2022
49fbb0f
remove obsolete logic which is now handled elsewhere
dummdidumm Aug 15, 2022
23f31be
implement invalidate()
dummdidumm Aug 15, 2022
3931be6
invalidate() should also loads without dependencies
dummdidumm Aug 15, 2022
8ad3f89
Update documentation/docs/05-load.md
Rich-Harris Aug 15, 2022
3e47589
Update documentation/docs/03-routing.md
Rich-Harris Aug 15, 2022
ce4cbc8
inject $types.d.ts files into code snippets where possible
Rich-Harris Aug 15, 2022
c1e2086
add a note about shared state. not 100% sure this is the best place f…
Rich-Harris Aug 15, 2022
07f008b
Update documentation/docs/05-load.md
Rich-Harris Aug 15, 2022
7fd96dc
document set-cookie exception
Rich-Harris Aug 15, 2022
190cbc2
Merge branch 'migrate-tests' of github.com:sveltejs/kit into migrate-…
Rich-Harris Aug 15, 2022
4ae261f
tweaks
Rich-Harris Aug 15, 2022
d59cd43
tweaks
Rich-Harris Aug 15, 2022
b64288d
more tweaks
Rich-Harris Aug 15, 2022
86f8e2b
cheat
Rich-Harris Aug 15, 2022
1a75afa
GET->load
dummdidumm Aug 15, 2022
d31da9f
more tweaks
Rich-Harris Aug 15, 2022
071bddd
fix create-svelte
dummdidumm Aug 15, 2022
e8795b6
more tweaks
Rich-Harris Aug 15, 2022
b8cdcb5
merge
Rich-Harris Aug 15, 2022
22b8804
Update documentation/docs/05-load.md
Rich-Harris Aug 15, 2022
343b72c
fixes
Rich-Harris Aug 15, 2022
6ee6b76
remove outdated Get reference
Rich-Harris Aug 15, 2022
40d1579
actions
Rich-Harris Aug 15, 2022
f262495
rewrite type names
Rich-Harris Aug 15, 2022
c9d8254
rename Load to PageLoad or LayoutLoad etc
Rich-Harris Aug 15, 2022
e2dbce1
include filename in migration scripts
Rich-Harris Aug 15, 2022
47e4b7c
updates
Rich-Harris Aug 15, 2022
6d4c24d
fix search
Rich-Harris Aug 15, 2022
4435a75
mention export let errors
Rich-Harris Aug 15, 2022
51900fc
changesets
Rich-Harris Aug 15, 2022
99690ae
fix types in create-svelte template
Rich-Harris Aug 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 7 additions & 6 deletions documentation/docs/02-web-standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,27 @@ An instance of [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Requ

#### Response

An instance of [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) is returned from `await fetch(...)`. Fundamentally, a SvelteKit app is a machine for turning a `Request` into a `Response`.
An instance of [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) is returned from `await fetch(...)` and handlers in `+server.js` files. Fundamentally, a SvelteKit app is a machine for turning a `Request` into a `Response`.

#### Headers

The [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) interface allows you to read incoming `request.headers` and set outgoing `response.headers`:

```js
// @errors: 2461
/// file: src/routes/what-is-my-user-agent.js
/// file: src/routes/what-is-my-user-agent/+server.js
/** @type {import('@sveltejs/kit').RequestHandler} */
export function GET(event) {
// log all headers
console.log(...event.request.headers);

return {
body: {
return new Response(
{
// retrieve a specific header
userAgent: event.request.headers.get('user-agent')
}
};
},
{ headers: { 'content-type': 'application/json; charset=utf-8' } }
);
}
```

Expand Down
360 changes: 196 additions & 164 deletions documentation/docs/03-routing.md

Large diffs are not rendered by default.

142 changes: 65 additions & 77 deletions documentation/docs/04-layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ So far, we've treated pages as entirely standalone components — upon navigatio

But in many apps, there are elements that should be visible on _every_ page, such as top-level navigation or a footer. Instead of repeating them in every page, we can use _layout_ components.

To create a layout that applies to every page, make a file called `src/routes/__layout.svelte`. The default layout (the one that SvelteKit uses if you don't bring your own) looks like this...
To create a layout that applies to every page, make a file called `src/routes/+layout.svelte`. The default layout (the one that SvelteKit uses if you don't bring your own) looks like this...

```html
<slot></slot>
Expand All @@ -15,7 +15,7 @@ To create a layout that applies to every page, make a file called `src/routes/__
...but we can add whatever markup, styles and behaviour we want. The only requirement is that the component includes a `<slot>` for the page content. For example, let's add a nav bar:

```html
/// file: src/routes/__layout.svelte
/// file: src/routes/+layout.svelte
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
Expand All @@ -28,17 +28,17 @@ To create a layout that applies to every page, make a file called `src/routes/__
If we create pages for `/`, `/about` and `/settings`...

```html
/// file: src/routes/index.svelte
/// file: src/routes/+page.svelte
<h1>Home</h1>
```

```html
/// file: src/routes/about.svelte
/// file: src/routes/about/+page.svelte
<h1>About</h1>
```

```html
/// file: src/routes/settings.svelte
/// file: src/routes/settings/+page.svelte
<h1>Settings</h1>
```

Expand All @@ -51,7 +51,7 @@ Suppose we don't just have a single `/settings` page, but instead have nested pa
We can create a layout that only applies to pages below `/settings` (while inheriting the root layout with the top-level nav):

```html
/// file: src/routes/settings/__layout.svelte
/// file: src/routes/settings/+layout.svelte
<h1>Settings</h1>

<div class="submenu">
Expand All @@ -67,7 +67,7 @@ We can create a layout that only applies to pages below `/settings` (while inher
Some parts of your app might need something other than the default layout. For these cases you can create _named layouts_...

```svelte
/// file: src/routes/__layout-foo.svelte
/// file: src/routes/+layout-foo.svelte
<div class="foo">
<slot></slot>
</div>
Expand All @@ -76,132 +76,120 @@ Some parts of your app might need something other than the default layout. For t
...and then use them by referencing the layout name (`foo`, in the example above) in the filename:

```svelte
/// file: src/routes/[email protected]
<h1>I am inside __layout-foo</h1>
/// file: src/routes/my-special-page/+page@foo.svelte
<h1>I am inside +layout-foo</h1>
```

Named layouts are very powerful, but it can take a minute to get your head round them. Don't worry if this doesn't make sense all at once.

#### Scoping

Named layouts can be created at any depth, and will apply to any components in the same subtree. For example, `__layout-foo` will apply to `/x/one` and `/x/two`, but not `/x/three` or `/four`:
Named layouts can be created at any depth, and will apply to any components in the same subtree. For example, `+layout-foo` will apply to `/x/one` and `/x/two`, but not `/x/three` or `/four`:

```bash
src/routes/
├ x/
│ ├ __layout-foo.svelte
│ ├ [email protected] # ✅ page has `@foo`
│ ├ [email protected] # ✅ page has `@foo`
│ └ three.svelte # ❌ page does not have `@foo`
[email protected] # ❌ page has `@foo`, but __layout-foo is not 'in scope'
│ ├ +layout-foo.svelte
│ ├ one/+page@foo.svelte # ✅ page has `@foo`
│ ├ two/+page@foo.svelte # ✅ page has `@foo`
│ └ three/+page.svelte # ❌ page does not have `@foo`
└ four/+page@foo.svelte # ❌ page has `@foo`, but +layout-foo is not 'in scope'
```

#### Inheritance chains

Layouts can themselves choose to inherit from named layouts, from the same directory or a parent directory. For example, `x/y/__layout@root.svelte` is the default layout for `/x/y` (meaning `/x/y/one`, `/x/y/two` and `/x/y/three` all inherit from it) because it has no name. Because it specifies `@root`, it will inherit directly from the nearest `__layout-root.svelte`, skipping `__layout.svelte` and `x/__layout.svelte`.
Layouts can themselves choose to inherit from named layouts, from the same directory or a parent directory. For example, `x/y/+layout@root.svelte` is the default layout for `/x/y` (meaning `/x/y/one`, `/x/y/two` and `/x/y/three` all inherit from it) because it has no name. Because it specifies `@root`, it will inherit directly from the nearest `+layout-root.svelte`, skipping `+layout.svelte` and `x/+layout.svelte`.

```
src/routes/
├ x/
│ ├ y/
│ │ ├ __layout@root.svelte
│ │ ├ one.svelte
│ │ ├ two.svelte
│ │ └ three.svelte
│ └ __layout.svelte
__layout.svelte
__layout-root.svelte
│ │ ├ +layout@root.svelte
│ │ ├ one/+page.svelte
│ │ ├ two/+page.svelte
│ │ └ three/+page.svelte
│ └ +layout.svelte
+layout.svelte
+layout-root.svelte
```

> In the case where `__layout-root.svelte` contains a lone `<slot />`, this effectively means we're able to 'reset' to a blank layout for any page or nested layout in the app by adding `@root`.
> In the case where `+layout-root.svelte` contains a lone `<slot />`, this effectively means we're able to 'reset' to a blank layout for any page or nested layout in the app by adding `@root`.

If no parent is specified, a layout will inherit from the nearest default (i.e. unnamed) layout _above_ it in the tree. In some cases, it's helpful for a named layout to inherit from a default layout _alongside_ it in the tree, such as `__layout-root.svelte` inheriting from `__layout.svelte`. We can do this by explicitly specifying `@default`, allowing `/x/y/one` and siblings to use the app's default layout without using `x/__layout.svelte`:
If no parent is specified, a layout will inherit from the nearest default (i.e. unnamed) layout _above_ it in the tree. In some cases, it's helpful for a named layout to inherit from a default layout _alongside_ it in the tree, such as `+layout-root.svelte` inheriting from `+layout.svelte`. We can do this by explicitly specifying `@default`, allowing `/x/y/one` and siblings to use the app's default layout without using `x/+layout.svelte`:

```diff
src/routes/
├ x/
│ ├ y/
│ │ ├ __layout@root.svelte
│ │ ├ one.svelte
│ │ ├ two.svelte
│ │ └ three.svelte
│ └ __layout.svelte
__layout.svelte
-└ __layout-root.svelte
+└ __layout[email protected]
│ │ ├ +layout@root.svelte
│ │ ├ one/+page.svelte
│ │ ├ two/+page.svelte
│ │ └ three/+page.svelte
│ └ +layout.svelte
+layout.svelte
-└ +layout-root.svelte
+└ +layout[email protected]
```

> `default` is a reserved name — in other words, you can't have a `__layout-default.svelte` file.
> `default` is a reserved name — in other words, you can't have a `+layout-default.svelte` file.

### Error pages

If a page fails to load (see [Loading](/docs/loading)), SvelteKit will render an error page. You can customise this page by creating `__error.svelte` components alongside your layouts and pages.
If a page fails to load (see [Loading](/docs/loading)), SvelteKit will render an error page. You can customise this page by creating `+error.svelte` components alongside your layouts and pages.

For example, if `src/routes/settings/notifications/index.svelte` failed to load, SvelteKit would render `src/routes/settings/notifications/__error.svelte` in the same layout, if it existed. If not, it would render `src/routes/settings/__error.svelte` in the parent layout, or `src/routes/__error.svelte` in the root layout.
For example, if `src/routes/settings/notifications/+page.svelte` failed to load, SvelteKit would render `src/routes/settings/notifications/+error.svelte` in the same layout, if it existed. If not, it would render `src/routes/settings/+error.svelte` in the parent layout, or `src/routes/+error.svelte` in the root layout.

> SvelteKit provides a default error page in case you don't supply `src/routes/__error.svelte`, but it's recommended that you bring your own.
> SvelteKit provides a default error page in case you don't supply `src/routes/+error.svelte`, but it's recommended that you bring your own.

If an error component has a [`load`](/docs/loading) function, it will be called with `error` and `status` properties:
An error component has no access to data retrieval mechanisms like pages or layouts to ensure nothing further can go wrong. You can use the [page store](/docs/modules#$app-stores-page) to display the status code and error message:

```html
<script context="module">
/** @type {import('@sveltejs/kit').Load} */
export function load({ error, status }) {
return {
props: {
title: `${status}: ${error.message}`
}
};
}
</script>

<script>
export let title;
import { page } from '$app/stores';
</script>

<h1>{title}</h1>
<h1>{$page.status}</h1>
<p>{$page.error.message}</p>
```

> Layouts also have access to `error` and `status` via the [page store](/docs/modules#$app-stores)
> Layouts also have access to `error` and `status` via the same page store
>
> Server-side stack traces will be removed from `error` in production, to avoid exposing privileged information to users.

You can further handle unexpected errors on the server using the [handleError](/docs/hooks#handleerror) hook.

#### 404s

Nested error pages are only rendered when an error occurs while rendering a specific page. In the case of a request that doesn't match any existing route, SvelteKit will render a generic 404 instead. For example, given these routes...

```
src/routes/
__error.svelte
+error.svelte
├ marx-brothers/
│ ├ __error.svelte
│ ├ chico.svelte
│ ├ harpo.svelte
│ └ groucho.svelte
│ ├ +error.svelte
│ ├ chico/+page.svelte
│ ├ harpo/+page.svelte
│ └ groucho/+page.svelte
```

...the `marx-brothers/__error.svelte` file will _not_ be rendered if you visit `/marx-brothers/karl`. If you want to render the nested error page, you should create a route that matches any `/marx-brothers/*` request, and return a 404 from it:
...the `marx-brothers/+error.svelte` file will _not_ be rendered if you visit `/marx-brothers/karl`. If you want to render the nested error page, you should create a route that matches any `/marx-brothers/*` request, and throw a 404 from it:

```diff
src/routes/
__error.svelte
+error.svelte
├ marx-brothers/
│ ├ __error.svelte
+│ ├ [...path].svelte
│ ├ chico.svelte
│ ├ harpo.svelte
│ └ groucho.svelte
```

```svelte
/// file: src/routes/marx-brothers/[...path].svelte
<script context="module">
/** @type {import('./__types/[...path]').Load} */
export function load({ params }) {
return {
status: 404,
error: new Error(`Not found: /marx-brothers/${params.path}`)
};
}
</script>
│ ├ +error.svelte
+│ ├ [...path]/+page.js
│ ├ chico/+page.svelte
│ ├ harpo/+page.svelte
│ └ groucho/+page.svelte
```

```js
/// file: src/routes/marx-brothers/[...path]/+page.js
import { error } from '@sveltejs/kit';
/** @type {import('./$types').Load} */
export function load({ params }) {
throw error(404, `Not found: /marx-brothers/${params.path}`);
}
```
Loading