Skip to content

Dev hot-reload of server-side modules is stale on Bun (query cache-bust ignored) #514

Description

@vivek7405

Problem

webjs's dev server picks up edits to server-side modules (route.ts, *.server.ts, page modules during SSR, WS exports) by re-importing them per request with a ?t=<timestamp> query cache-bust (loadWsModule, handleApi, the dev SSR module load). Node honors a changed import query as a fresh module; Bun's ESM loader ignores the query string and returns the cached module, and Bun exposes no module-eviction API. So on Bun, editing a server-side module is not reflected until a dev-server restart.

Verified on Bun 1.3.14: import(url + '?t=1') then import(url + '?t=2') after editing the file returns the FIRST module's exports on Bun (Node returns the second). Surfaced by the #509 Bun test matrix (the api dev-cache-bust test).

Component / page / layout SOURCE edits hot-reload fine on Bun, because the served .ts/.js is read from disk per request (tsResponse / jsModuleResponse), not imported. Only the server-side module EXECUTION path is affected.

Design / approach

No clean webjs-side fix exists today (query cache-bust is the standard ESM trick and Bun ignores it; a unique-path copy breaks relative imports inside the module). Options to investigate when Bun support lands or a workaround emerges:

  • Track Bun's module-registry / HMR APIs (e.g. import.meta.hot, a programmatic eviction) and wire the dev re-import to it on Bun.
  • A Bun-specific loader/plugin that re-evaluates a changed module's source.

Blocked on Bun upstream for now; documented as a known limitation in agent-docs/testing.md.

Acceptance criteria

  • On Bun dev, editing a route.ts / *.server.ts / page module is reflected on the next request without a restart (parity with Node dev).
  • A cross-runtime test proves the server-module reload on Bun.
  • The known-limitation note in agent-docs/testing.md is removed once fixed.

Activity

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions