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.

[feat] easier creation of metadata / `stuff`

See original GitHub issue

Describe the problem

Right now if you want to pass data from child to layout you do it via stuff. A common usecase is defining metatags. It can be a bit verbose to write this:

<script context="module">
  /** @type {import('@sveltejs/kit').Load} */
  export async function load({ stuff }) {
    return {
      stuff: {
        metadata: {
          description: 'page description here'
        }
      }
    };
  }
</script>

Describe the proposed solution and alternatives considered

Option 1

Take anything not in a known property and add it to stuff. Or potentially only properties whitelisted by the user. Then you could save a few lines of code:

<script context="module">
  /** @type {import('@sveltejs/kit').Load} */
  export async function load({ stuff }) {
    return {
      metadata: {
        description: 'page description here'
      }
    };
  }
</script>

The downside to this of course is that if we add any new property to the return value it’s potentially a breaking change. But we might be willing to make that tradeoff if the improvement in ergonomics is deemed sufficient and we felt it was unlikely we’d introduce many new fields to the return value

Option 2

Having stuff is nice because you can control the contents based on data dynamically fetched from the server. However, much of the time that is unnecessary and the data is simply static. It could also be nice if you could write something like this in the child node:

<script context="module">
  export const metadata: {
    description: 'page description here'
  };
</script>

We could make the leaf node available to load.

Option 3

Similar to option 2, but instead of making just the leaf node available, we could make an object with the fields in each layout / child with the children overriding the parents and then make it available in load. The trickiest part of this would probably be how to refer to it and differentiate it from stuff in the API

Option 4

Create a new variable like statics that you can define outside of load that SvelteKit will make available in load. This is similar to the last option in some ways, but only works with a single SvelteKit-defined property

Importance

nice to have

Additional Information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mrkishicommented, Feb 27, 2022

Seconding Con on this one, especially as we would lose forwards compatibility since any added properties would be breaking changes. Well, I guess they wouldn’t be breaking in the whitelisting case, but it’d still be a hassle for little upside.

Having direct access to the module so you can get exported data might be less troublesome, although I’m not sure whether it’d come with its own set of warts.

1reaction
Conduitrycommented, Feb 27, 2022

I really don’t like “any unknown options get treated as such-and-such” APIs. That would include “everything that’s not one of the known load return keys gets put into stuff” and “every module export from the component that’s not load/ssr/prerender/etc. gets put into stuff”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Ultimate Guide to Music Metadata - Soundcharts
When people hear music metadata, they think of artist name, song name, cover art on their iTunes music library. Well, in fact, the...
Read more >
Metadata Creation/Archival Description
Creating metadata involves students tagging and describing digital materials. This process can then illuminate the process that goes into making materials ...
Read more >
HOW METADATA CAN HELP MEDIA COMPANIES SUCCEED
Producing, managing and distributing content is no simple feat, and metadata impacts all of those tasks. It's no longer enough to distribute content...
Read more >
[See Description] How to make NFT Art with On-Chain Metadata
NOTE! Rinkeby is outdated; please use Goerli! ...
Read more >
How to Use Metadata to Grow Your YouTube Channel - BBTV
Creating a strong SEO backbone by optimizing your metadata is no small feat. When you've already taken the time to create great content,...
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