Skip to content

Environment API experiments - #1

Open
Rich-Harris wants to merge 63 commits into
mainfrom
environment-api
Open

Environment API experiments#1
Rich-Harris wants to merge 63 commits into
mainfrom
environment-api

Conversation

@Rich-Harris

@Rich-Harris Rich-Harris commented Sep 21, 2024

Copy link
Copy Markdown
Owner

this is just a place to experiment with the work started in sveltejs#12637

thoughts, in no particular order:

  • if we use a pragma to declare which runtime belongs to which route, we can put it in the manifest data
  • maybe adapters should be able to influence the Vite config (in addition to creating environments, they could set aliases etc)? Then again there probably aren't many things they should be responsible for, so the conservative thing to do would be to just rely on them to create environments yeah I'm pretty sure this is a no
  • we need to be able to use alternative runtimes during postbuild and preview. this feels a bit 'draw the rest of the owl' right now
  • there's way too much boilerplate — it should be possible to make the entry points way simpler. like, maybe instead of importing Server and instantiating it with other stuff you imported, you should just import server and it should come with properties like base and methods like server.isAsset(request) and server.isPrerendered(request) already configured
  • feels like adapters shouldn't have to worry about getClientRequest in dev
  • same for read — in prod the adapter needs to provide an implementation, but in dev surely it only needs to say whether or not it's supported (and this should mean we no longer need all the finicky AsyncLocalStorage/before_handle stuff to determine whether or not it's being used in a route that doesn't support it)
  • we can deprecate request.platform and the emulate function on adapters, neither is needed in this new world

thoughts on the Environment API itself

  • wow this is complicated. the ontology is huge
  • wow there's a lot of boilerplate
  • feels awkward that we need to jump through hoops to make a Node environment API that we can use for SSR. This seems like such a core use case. The dispatchFetch stuff feels ropey
  • the process of creating a ModuleRunner seems very elaborate. would love to see a much simpler API here

@dummdidumm

Copy link
Copy Markdown

we can deprecate request.platform and the emulate function on adapters, neither is needed in this new world

I think they are still important:

  • request.platform is still important for stuff that's per-request and not globally available
  • emulate IMO is a good way for each adapter to provide an entry into its own environment setup (e.g. the stuff that's currently in dev/default_environment.js etc). As seen in our middleware explorations it might also not be enough to say "ok this is the environment, and I'm gonna call you now", for middleware we might also want to be able to provide hooks into the request/response lifecycle beforehand

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.

3 participants