new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Vite · Guide · all subjects

environment api/fetchabledevenvironment

8 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

FetchableDevEnvironment purpose

FetchableDevEnvironment is an environment that can communicate with its runtime via the Fetch API interface. It is recommended over RunnableDevEnvironment for frameworks that want to support runtimes that cannot run Vite directly (e.g. Cloudflare Workers). A RunnableDevEnvironment cannot be used in those runtimes since it requires the runner to share the Vite server's runtime.

FetchableDevEnvironment handleRequest handler

Create a FetchableDevEnvironment using createFetchableDevEnvironment(name, config, { handleRequest(request: Request): Promise<Response> | Response { ... } }). The handleRequest function receives a Request object and must return a Response or Promise<Response>. Call server.environments.custom.dispatchFetch(new Request(...)) to send requests to the environment.

FetchableDevEnvironment validation

Vite validates the input and output of the dispatchFetch method: the request must be an instance of the global Request class and the response must be an instance of the global Response class. Vite will throw a TypeError if this is not the case.

isFetchableDevEnvironment function

Use the isFetchableDevEnvironment function to check if an environment is a FetchableDevEnvironment before calling dispatchFetch.

CachedFetchResult interface

CachedFetchResult is analogous to HTTP 304 (Not Modified) status code and has one property: cache (boolean, value true). When returned, it confirms the module is cached in the runner and was not invalidated on the server side.

ExternalFetchResult interface

ExternalFetchResult instructs the module runner to import the module using the runExternalModule method on the ModuleEvaluator. It has: externalize (string, required, path to externalized module starting with file://, imported via dynamic import by default instead of being transformed by Vite), and type ('module' | 'commonjs' | 'builtin' | 'network', required, used to determine if import statement is correct and to throw errors if variables are not actually exported).

ViteFetchResult interface

ViteFetchResult returns information about the current module with: code (string, required, code evaluated by Vite runner, wrapped in async function by default), file (string | null, required, file path of module on disk, resolved as import.meta.url/filename, null for virtual modules), id (string, required, module ID in server module graph), url (string, required, module URL used in import), and invalidate (boolean, required, instructs module runner to invalidate module before executing rather than serving from cache, usually true when HMR update triggered).

FetchResult union type

FetchResult returned by environment.fetchModule is a union of CachedFetchResult, ExternalFetchResult, and ViteFetchResult, meant to be consumed by the module runner.

Give your agent this brain