fix: eagerly initialise dynamic env vars from process.env at module-eval time - #16303
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/91afeeed060aede8c09439926c818ec6f8d297f8Open in |
🦋 Changeset detectedLatest commit: 91afeee The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
90d3458 to
a436ecb
Compare
8b29742 to
4a96498
Compare
a436ecb to
2b5ae26
Compare
7ba2ae9 to
348e72d
Compare
265a930 to
3508875
Compare
|
Tested this branch against the repro for #16288 (adapter-node + The facade written in |
|
Yeah, this is still a draft, not ready yet 😅 |
2b5ae26 to
fc13f64
Compare
fc13f64 to
eb39e12
Compare
3508875 to
572d1d8
Compare
e17ef38 to
c80e50c
Compare
c80e50c to
893192a
Compare
893192a to
ff50f3e
Compare
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
… elliott/eager-env-init
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
closes #14286
Dynamic
$app/envvalues are normally populated whenServer.init()callsset_env(). The problem is thatinstrumentation.server.jsdeliberately runs beforeServer.init(), so importing$app/envthere gives youundefined. More subtly, instrumentation can share a chunk with application code and cause that code to evaluate early too, permanently capturing those undefined values at module scope.Basically, instrumentation should run before the application, but not before the minimum runtime state it is allowed to observe exists.
This adds an environment initializer to
builder.instrument(). Adapters provide the final env module location and generate the small platform-specific initializer; Kit handles the relative import, imports it before instrumentation, and only then dynamically imports the application entrypoint. The same ordering now applies in dev and preview.The official adapters initialize from their native runtime source:
process.envenvfromcloudflare:workersDeno.env.toObject()Added tests for generated import paths, custom facades, module evaluation order, filename collisions, and a built adapter-node app reading dynamic env at instrumentation module scope.