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

Accumulate data #6050

Merged
merged 9 commits into from
Aug 18, 2022
Merged

Accumulate data #6050

merged 9 commits into from
Aug 18, 2022

Conversation

Rich-Harris
Copy link
Member

Closes #5994.

Today, if you have a page with a load...

// src/routes/foo/+page.js
export function load() {
  return {
    pagedata: 'hello from page load'
  };
}

...then the corresponding data prop will contain pagedata and nothing else. If you have some data from a layout load function that you need in the page, you need to call await parent() in the page's load:

// src/routes/foo/+page.js
-export function load() {
+export async function load({ parent }) {
+  const { layoutdata } = await parent();
  return {
+    layoutdata,
    pagedata: 'hello from page load'
  };
}

As of this PR, that's no longer the case — layout data will automatically be inherited (with correct types!) so that you can reference data.layoutdata (or, more realistically, data.user.name) throughout your app without boilerplate.

Please don't delete this checklist! 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 pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

Sorry, something went wrong.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Partially verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
@changeset-bot
Copy link

changeset-bot bot commented Aug 18, 2022

🦋 Changeset detected

Latest commit: b64a449

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

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I left three things that probably need a change, also the docs should probably mention this

@tsukhu
Copy link

tsukhu commented Aug 19, 2022

Thank you for this update. I have deleted 3 +page.ts files now :-)

@rohanrajpal
Copy link

Love this!

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.

Accumulate data into export let data
4 participants