-
-
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
Layout Stack not Fully Reset for src/routes/__layout.svelte #2154
Comments
Hey, Thanks ✌ const c = [
() => import("..\\..\\..\\src\\routes\\__layout.svelte"),
() => import("..\\components\\error.svelte"),
() => import("..\\..\\..\\src\\routes\\index.svelte"),
() => import("..\\..\\..\\src\\routes\\login\\__layout.reset.svelte"),
() => import("..\\..\\..\\src\\routes\\login\\index.svelte")
];
const d = decodeURIComponent;
export const routes = [
// src/routes/index.svelte
[/^\/$/, [c[0], c[2]], [c[1]]],
// src/routes/login/index.svelte
[/^\/login\/?$/, [c[3], c[4]], []]
];
export const fallback = [c[0](), c[1]()]; |
The Svelte docs for And @anudeepreddy, you're right that the
Since the fallback error page uses the root layout as its rendering, that means that the root layout is always imported, and any module-level side effects (such as a However, any subsequent layout pages that are reset will not be imported (and their module context will not be run). For example, I took @jsprog's repro code and added the following files to it:
The contents of those layout pages were similar to the other layout pages in the repro: a console.log call in both the module and instance scripts. And when I loaded http://localhost:3000/foo/bar/ and looked in the console log, I saw that the So I believe this is not actually a bug in the layout reset process, but rather a side effect of the error components always using the root layout, which means that the root layout is always imported and so its module context script is always executed. (Note that if you provide your own |
That comment turned out a bit long. The short version is that layouts are being properly reset (see my Therefore, if you have any side-effecting code in the module-context script of your root layout, it will always run because that module will always be imported. But at any level below the root, the layout module is not imported unless it's going to be used for rendering, so module-context script at any level below the root won't be run if there's a lower |
Shouldn't we export the fallback array as functions, and change the usage in Renderer so that we can import them when they are actually required and not on every page reload as we do now. This approach also seems to solve #2130. |
The current implementation plays against the purpose behind the existence of code splitting. Developers should be allowed to bring some complex components to the main layout without bloating the login page (e.g: complex header containing menus and dialogs). The following screenshots were taken after updating the reproduction code with more files: |
Another Note: both |
According to #1356 (comment) it's deliberate to have the fallback components (the root layout and error components) imported during initial load, even if they're not used, precisely because they are fallback components. If something goes wrong in the process of loading a page, one of the likely reasons why it went wrong is a network failure, in which case loading the error components will fail too if they aren't already in the user's browser. That is why the root layout and error components are imported as soon as possible, so that they will be in memory in the user's browser and available to use without any further network traffic. Which means that if the network goes down five seconds after the user loads your site's first page, there's at least something that Svelte-Kit can display to inform them that the site isn't working right. Therefore, this behavior is unlikely to change, and the only real fix to this issue is going to be to add a note to the documentation saying "Don't put side effects in the root layout module script, as they might be run when you don't expect them to run." |
This is a problem for me. While I can avoid side effects by not placing any actions at the module level in
No page should be hardwired to the default layout, which is highly likely to be used for non-trivial purposes. The same applies to In the current case, it's a bit trickier because the fallback page is automatically generated, but I think it would be better not to use any layout by default, and provide a way to configure the layout for the error page by:
As of now, I'm seriously considering changing all my pages to use explicitly named layouts to avoid any more problems with |
@jsprog are you still facing this since the introduction of named layouts? If so, could you update the description and reproduction? |
Confirmed that this still happens in the latest version. The culprit is this: kit/packages/kit/src/runtime/client/client.js Lines 25 to 28 in ab65de0
I'm not sure what the best fix here is without sacrificing this behavior - only do it when we know there's only a single root layout? Is this logic even necessary? If there are connectivity issues, what's gained from rendering the root layout? It makes more sense for the root error for me, but when named errors are implemented, we'll get the same problem there. The only case where this is benefitial is when you navigate the app, connection breaks down, and you haven't loaded the default root layout yet. Is it possible to somehow prefetch the code, but not execute it yet? |
#6124 Closes #6196 (using (groups) and/or composition) Closes #5763 (root layout guaranteed to always exist + await parent()) Closes #5311 (+page@.svelte) Closes #4940 (no longer possible to get into this situation) Closes #2154 (only a single root layout now) Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com> Co-authored-by: Dominik G. <dominik.goepel@gmx.de> Co-authored-by: Ignatius Bagus <ignatius.mbs@gmail.com> Co-authored-by: Conduitry <git@chor.date>
Describe the bug
According to the official sveltekit documentation, adding __layout.reset.svelte inside a nested folder should reset layout stack and prevent inheriting from upper level layouts. Unfortunately, the browser is receiving some logs from the module context of
__src/routes/__layout.svelte
. ssr logs are clean and not affected.Reproduction
src/routes/login/__layout.reset.svelte
should resetsrc/routes/__layout.svelte
.localhost:3000/login
, you'll notice the log from the module context ofsrc/routes/__layout.svelte
is still there.Logs
No response
System Info
Severity
annoyance
Additional Information
__layout.reset.svelte
are fully resetting them.The text was updated successfully, but these errors were encountered: