-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Explicit fallthrough #3217
Explicit fallthrough #3217
Conversation
🦋 Changeset detectedLatest commit: ef33ab1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
❌ Deploy Preview for kit-demo failed. 🔨 Explore the source changes: 05ebc5a 🔍 Inspect the deploy log: https://app.netlify.com/sites/kit-demo/deploys/61d9b85a1322ac00085ff35f |
Thank you. My first reaction was that this could be confusing — it's much more likely that you'd simply forget to return something from But you could easily argue that the same is true for pages and endpoints. I've definitely been caught out by that once or twice (i.e. 404s that I wasn't expecting). So I was wondering if we shouldn't make it explicit — make the return value required (i.e. <script context="module">
async function load({ params }) {
if (params.foo !== 'okay') {
return { fallthrough: true };
}
return {};
}
</script> Thoughts? |
The implicit fallthrough when nothing is returned is indeed a bit confusing. I'll change that to your proposed solution. When export interface LoadOutput<
Props extends Record<string, any> = Record<string, any>,
Stuff extends Record<string, any> = Record<string, any>
> {
status?: number;
error?: string | Error;
redirect?: string;
props?: Props;
stuff?: Stuff;
maxage?: number;
} | {fallthrough: boolean } Or is it enough to point this behavior out in the docs? |
It definitely should be reflected in the types 👍 |
It should be kit/packages/kit/types/endpoint.d.ts Lines 12 to 18 in a59c89f
|
Fallthrough is now explicit as suggested by @Rich-Harris. In order to reflect this in the types I added an |
adapted changeset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is looking good — just a couple of small things I found
Co-authored-by: Rich Harris <hello@rich-harris.dev>
✔️ Deploy Preview for kit-demo canceled. 🔨 Explore the source changes: ef33ab1 🔍 Inspect the deploy log: https://app.netlify.com/sites/kit-demo/deploys/61dca2d19ee5fa00071b2803 |
thank you! |
This PR makes fallthrough explicit. Only if
{fallthrough: true}
is returned by a load function or an endpoint the fallthrough mechanism is triggered. This way it is more clear when fallthrough is applied.Fixes #2440 by allowing the same fallthrough logic that is used for page components.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0