Skip to content

Update preloadCode API #16511

Description

@Rich-Harris

Describe the problem

preloadCode is a bit of an odd API — it loads data for a route, but accepts a pathname as its argument. If you don't yet know the pathname, then you can just shove in any old string. The docs suggest that if you want to preload the code for /blog/[slug] you could call preloadCode('/blog/*'). This is obviously very kludgy!

Describe the proposed solution

Given that we now export an array of routes from $app/manifest, it feels like maybe it would be better if preloadCode accepted a RouteId instead:

await preloadCode('/blog/[slug]');

If you did have a pathname, you could always do this:

const matched = await match('/blog/hello');
await matched && preloadCode(matched.id);

Alternatives considered

A valid response would be 'eh, it's fine, why bother changing it'. Which is fair. I'm probably the only person who cares about this. It would likely involve some finicky work, and the match solution is probably more waterfally than what we have now?

But if we were to change the API on account of its inherent weirdness, now would be the time.

Importance

nice to have

Additional Information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions