Programmatic render API #16371
Rich-Harris
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
This isn't a fleshed out thought — I'm thinking it as I type it — but reading #16368 made something click for me. At the moment the way to add custom bits and bobs to a response in SvelteKit is to use
handle, where theresolvefunction defaults to 'what the framework was going to do anyway':If you want a stack of middlewares, you use
sequence, in which caseresolvemeans 'the next handler after mine':So far so whatever. It starts to get a little confusing when your needs become more involved, as shown in the sequence docs — suddenly you have to learn things like 'transforms are applied in reverse order' and that some options like
preloadcan only be invoked once, by the first handler that happens to define them.It's also just a little... I don't know, ugly.
Meanwhile — and this will seem totally disconnected, bear with me — we have occasionally wondered about having a way to render pages programmatically, particularly for the sake of service workers, but maybe it would be useful in other contexts (particularly old-fashioned form submissions, where if you're not using page actions or remote functions for whatever reason, you can't respond with a rendered page — the best you can do is redirect).
So what if we exposed something like
respond?You could also use
$app/routerin e.g.+server.tshandlers, and ideally in service workers (though that's a little trickier since you would still need to go back to the server sometimes to fulfil a request; you couldn't ship private env vars or database clients to your service worker but you could ship e.g. a remote function that didn't use anything sensitive).Like I say, not fleshed out at all. I haven't suggested a good pattern for passing context between middlewares, for example. And now that I've written it, clearly more involved than something we want to block 3.0 on. But maybe there's something there?
All reactions