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

[fix] deeply-nested error components render with correct layout #2389

Merged
merged 1 commit into from
Sep 8, 2021

Conversation

rmunn
Copy link
Contributor

@rmunn rmunn commented Sep 8, 2021

Under some circumstances, a deeply-nested error component could render with a layout from a parent folder instead of the layout from the error component's own folder. This commit fixes that bug, so that error components are correctly matched up with layout components in the same folder even when deeply nested.

Fixes #2383.

Before submitting the PR, please make sure you do the following

  • 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

Under some circumstances, a deeply-nested error component could render
with a layout from a parent folder instead of the layout from the error
component's own folder. This commit fixes that bug, so that error
components are correctly matched up with layout components in the same
folder even when deeply nested.
@changeset-bot
Copy link

changeset-bot bot commented Sep 8, 2021

🦋 Changeset detected

Latest commit: c0b30df

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@rmunn
Copy link
Contributor Author

rmunn commented Sep 8, 2021

The root cause was modifying error_stack in place in the create_manifest_data function. Under certain conditions, which #2383 reproduces, error_stack could contain [ root_error, undefined, undefined, nested_error ] and the correct logic would be to remove precisely one undefined from that array, but not two. But because error_stack was being modified in place rather than a copy being made and the copy modified, the first pass through the loop would correctly remove a single undefined to produce [ root_error, undefined, nested_error ], but the second pass through the loop would again remove a single undefined to produce [ root_error, nested_error ]. The second pass through the loop would therefore produce an error stack that was out of sync with the component stack, and the error would then be rendered in the wrong layout.

By making a copy of the error_stack array and modifying the copy, both passes through the loop start with [ root_error, undefined, undefined, nested_error ] and therefore both passes correctly produce [ root_error, undefined, nested_error ], which lines up the nested_error component correctly with the layout it's supposed to be rendered with.

@benmccann benmccann merged commit d5ac08b into sveltejs:master Sep 8, 2021
@benmccann
Copy link
Member

thanks!

This was referenced Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

__error.svelte renders in the wrong layout
2 participants