question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accumulate data into `export let data`

See original GitHub issue

Describe the bug

This is an “opinionated” take on the recent changes to routes and load function behavior. It’s a big change, that I am not a fan of but can see the merit. Among other things it now requires more boilerplate code, which we all don’t like to deal with.

Here’s the problem: +page.svelte doesn’t receive data unless there’s +page.ts file with load function even though we might have data set by parent layouts. This forces one to create a bunch of +page.ts files with a the following boilerplate. Wouldn’t be nicer to do that as a default for all pages, so we don’t have to create +page.ts files unless we’re actually doing something specific there?

import type { PageLoad } from './$types';

export const load: PageLoad = async ({ parent }) => {
  return await parent();
};

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-f8ky2l?file=src/routes/+page.js

The +page.js file seems to be completely unnecessary but you can’t remove it or +page receives no data.

Logs

No response

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /bin/yarn
    npm: 7.17.0 - /bin/npm
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.64 
    @sveltejs/kit: next => 1.0.0-next.416 
    svelte: ^3.46.0 => 3.49.0 
    vite: ^3.0.0 => 3.0.8

Severity

serious, but I can work around it

Additional Information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Rich-Harriscommented, Aug 17, 2022

Our ultimate responsibility is to end users. We don’t want to make it easy to build fast sites, we want to make it hard to build slow sites. It doesn’t matter how conscientious individual developers are — if you have slowness baked into the system, optimizing it away will forever be on the backlog.

That said, we realised that we can merge data without affecting the ability to run load functions concurrently. Rendering doesn’t begin happening until loading is complete, which means that each layout/page node can be rendered with the equivalent of { ...await parent(), data }. In that case PageData would include types of the parent data as well.

2reactions
babichjacobcommented, Aug 17, 2022

This is less work now than it used to be.

You can use $page.data to get data from ancestors and/or children without writing a load function and thereby +page.js file at all.

<!-- src/routes/+page.svelte (from the reproduction link). Could also be used in src/routes/+layout.svelte or any component, for example -->
<script>
  import { page } from "$app/stores";
</script>

<div>
{JSON.stringify($page.data)}
</div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Modern JavaScript – Imports, Exports, Let, Const, and ...
In summary: In ES6, data declared in one file is not accessible to another file until it is exported from that file and...
Read more >
Export data from a Power BI visualization - Microsoft Learn
This article shows you how to export to Excel. Data can be exported to Excel from a Power BI dashboard tile and from...
Read more >
How can I pass data from one export function to another ...
1 Answer 1 · 1. Separate your code logic from your "cloud functions" · 2. Keeping the cloud functions separate and triggering another...
Read more >
How To Export Underlying Data in Power BI - DesignMind
You should export summarized data when you want to see the relevant data in the visualization. Summarized data will only show the columns...
Read more >
Solved: Sum of Distinct count is not matching with export
Sum of Distinct count is not matching with export data, row by row there is no ... Can you please let me know...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found