Remove dead code from the bake HMR runtime - #43828
Conversation
hmr-module.ts: remove hasExportStar, the commented-out export check that was its only caller (disabled since #18109), and the availableExportKeys local that only that check read. client/websocket.ts: remove the firstConnection local. Nothing reads it.
|
Updated 10:57 PM PT - Sep 22nd, 2026
❌ @robobun, your commit b3276f7 has 1 failures in
🧪 To try this PR locally: bunx bun-pr 43828That installs a local version of the PR into your bun-43828 --bun |
|
Status: ready for review. The diff is green. The one red CI job does not come from this change. How this was verified:
CI on
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: oven-sh/bun/.coderabbit.yaml Review profile: ASSERTIVE Plan: Essentials Run ID: 📒 Files selected for processing (2)
💤 Files with no reviewable changes (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. WalkthroughThe changes remove an unused local from WebSocket initialization and remove imported-key validation and its export-star search helper from ESM dependency parsing. ChangesWebSocket cleanup
ESM dependency parsing
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The inspected removals leave WebSocket connection handling and ESM dependency parsing unchanged. No merge-blocking risk was identified. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
Problem
hasExportStarinsrc/runtime/bake/hmr-module.tshas no caller. Its only call site is a block that fix dev server regressions from 1.2.5's hmr rewrite #18109 commented out on 2025-03-14. TheavailableExportKeyslocal above that block is read only by the commented-out code.firstConnectioninsrc/runtime/bake/client/websocket.tsis assigned once and never read.tsc --noUnusedLocalsoversrc/jsandscriptsonly, not oversrc/runtime/bake.Fix
hasExportStar, the commented-out check,availableExportKeys, andfirstConnection. 2 files, 40 lines removed.hasExportStar. The generatedbake.client.js,bake.server.jsandbake.error.jsdiffer frommainonly by the two removed local declarations.tsc -p src/runtime/bake/tsconfig.json --noUnusedLocalsno longer reports either file.test/bake/dev/esm.test.ts(17 pass),hot.test.ts(11 pass) andbundle.test.ts(23 pass) with the debug build.Behaviour change: none
Background
hmr-module.tsis the module loader that the dev server sends to the browser and to the SSR realm.parseEsmDependencieswalks the dependency list of an ES module. Each entry carries the export names that the importer uses.SyntaxErrorfor a missing one. It has been off for 18 months. A missing export fails at the use site.Downsides
Notes
Why this run is small
Every other hit of this run is live, is platform code with a user on another target, or is a line that one of the 34 open dead-code pull requests already deletes. Each removed line here was checked against those diffs. #40492 and #43378 touch
websocket.tsin other hunks.Scans of this run, all clean or already claimed
--gc-sections --print-gc-sections, thenllvm-symbolizerforfile:line. 20,668 discarded functions in bun's objects. The Rust ones outside macros and trait impls are Windows or macOS helpers, or claimed (Remove dead code from bun_jsc, bun_runtime, bun_core, and the JSC bindings #40824, Remove dead code from the inspector protocol package, bun_jsc, bun_install, and the Windows named pipe modules #40557, Remove dead code from the JSC bindings, headers.h, the console builtin, and bun_jsc #40232). The C++ ones are claimed, are template instantiations, or have a Rust caller on another target (bsd_socket_export,posix_spawnattr_reset_signals).#[inline], never instantiated), found by comparing everyfnline with the DWARF declaration lines of all emitted functions. 86 hits outsidecfg, trait impls and#[inline(always)]. All are Windows-only, test-only (the outbound half ofapi/bun/h2/connection.rs), or claimed.clang -fsyntax-only -Wunused-function -Wunused-macros -Wunused-template -Wunused-member-functionover 588 translation units and the 69 unified ones (the build passes-Wno-unused-function). 3 functions and 6 macros.formatStackTraceToJSValueWithoutPrepareStackTrace,hostName,G_TRUE,G_FALSE,MAX_LABELSandus_ioctlare claimed (Remove dead code from bun_core, bun_jsc, bun_css, react_compiler, and two C++ bindings #40367, Remove dead code from the class and sink generators, JSBuffer, the bake client, bun-error, and the build scripts #43378, Remove dead code from the JSC bindings, the codegen scripts, the CI scripts, bun_core, and bun_jsc #40492, Remove dead code from bun-uws, bun-usockets, the require.extensions FFI, and unused Cargo dependencies #40294).us_quic_send_oneis used under the non-Linux#ifbranch.c-index-test -index-file, 657 translation units, 32,018 symbols declared in bun's tree). 8,711 have no recorded reference. After filters for template-dependent uses,extern "C", virtual methods and names that WebKit headers use, 78 remain. All are index artifacts (typedef struct tags, primary templates with used specializations,requiresclauses) or one-line getters in files that open pull requests rewrite.tsc --noUnusedLocalsoversrc/js,scripts,src/codegen,src/runtime/bake,src/node-fallbacksand the sources of each package. The hits outside this change are claimed (Remove dead code from the build scripts, the vscode and debug-adapter packages, the bake overlay, and two WebCore files #40122, Remove dead code from bun_url, bun_react_compiler, the class codegen, and bun-error #41169, Remove dead code from bun_core, the JSC bindings, the debugger, and 24 other crates #41385, Remove dead code from the JSC bindings, the codegen scripts, the CI scripts, bun_core, and bun_jsc #40492, Remove dead code from the WebCore bindings, the WebView backends, and the build scripts #43778) or are loop variables.boolorOptionfields that only ever get one constant. Nothing new after Remove dead code: write-only fields and never-set options in 11 crates #43745.src/jsmodules and builtin functions with no mention in another file: none..idlcopies (Remove dead code from the inspector agent, the WebKit IDL copies, and an orphaned package #41064).src/symbols.txt,symbols.defand thepackage.jsonscripts name nothing that is gone. No#if 0.no test proof · iteration 1 · the description declares no behaviour change, so there is no failing test to prove; the existing suite in CI is the check