-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Support named layouts for the error page, e.g., __error@root.svelte, to remove hardwired dependency on __layout.svelte #4582
Comments
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
Popping in to say I'm glad the nightmare I'm currently enduring is being addressed ha ha. For what it's worth to me it feels as thought the best solution would be to just have say |
For anyone lost in the weeds, there's a decent workaround for handling full-screen error page layouts documented here with example implementation here. It's a fairly non-invasive procedure. Not perfect but not too shabby while a suitable long-term solution is considered. |
Sadly This causes issues when the extending layout or error page relies on things that are initialized in the base layout. This is a big inconsistency and layout inheritance should work the same way it does for page components IMO. |
If you use nested layouts at all at the root-level, error pages are completely broken right now pretty much. You end up having to import the same things in the error that should've already been imported by the parent layouts of the base layout. |
I think there is a easier work-around than vhscom mentions above: <script>
import { page } from '$app/stores'
</script>
{#if $page.error}
<div class="your-error-layout">
<slot></slot>
</div>
{:else}
<div class="your-normal-layout">
<slot></slot>
</div>
{/if} I end up with issues using the other method since it modifies the Request stream. |
I think it's possible that we'll want to add src/routes/
├ (main)
│ ├ foo/
│ ├ bar/
│ ├ etc/
│ ├ +layout.svelte # can safely throw errors in here
│ └ +page.svelte
├ +error.svelte
└ +layout.svelte # optional |
It appears that the "named layouts" feature is gone? https://kit.svelte.dev/docs/layouts#named-layouts - I now get a 404 I thought that was one of the slickest features pre "+layout" svelte-kit. |
Named layouts have been replaced by layout groups, which is a much more powerful and flexible concept. This issue is still open because (afaik) you can't apply certain features of layout groups, namely bailing from the current group with |
Describe the problem
Currently,
__error.svelte
is hardwired to__layout.svelte
. In several of my projects, I use__layout.svelte
for non-trivial purposes, including authentication guards, and of course rendering part of the page. This makes it nearly impossible to use__error.svelte
to set up a global error page:I've tried to work around this by saving the error information and redirecting to a normal page to display the error, but the approach is cumbersome and fraught with problems:
__layout.svelte
, that the error page is running. The URL path is the (possibly bad) path of the page that triggered the error.This has been a nightmare. I couldn't get it to work--I kept running into cascading issues--so I gave up (see Alternatives, below).
Describe the proposed solution
A simple solution would be to allow the error page to specify a parent layout (just like any other page, with the new named layouts):
__error@root.svelte
This could be an empty layout, which would remove dependencies on other parts of the app, making the error page less likely to fail. Similar to 2694 but adapted for the new named layouts.
Alternatives considered
Using a catch-all path in the route root will capture any unknown page, and this can specify a named layout:
[...anypath]@root.svelte
But this will not have access to actual error information, such as the stack trace, in development.
Importance
would make my life easier
Additional Information
The new named layouts were a bit hard to understand at first, but they are extremely powerful, and I'm sold on this. Fixing this would complete the picture, IMHO. As always, thanks to everyone for your hard work.
The text was updated successfully, but these errors were encountered: