Fix HMR import.meta.hot for Bun static analysis #1

Merged
defunkt merged 1 commits from probablycorey/forge:fix/hmr-static-analysis into main 2026-01-21 00:02:47 +00:00
Contributor

Bun's bundler treats import.meta.hot as a compile-time feature, not a regular JS property. When you use optional chaining
(import.meta.hot?.dispose(...)), Bun can't statically determine whether to include or exclude the HMR code.

By using a direct conditional instead, Bun can see at compile time that the block should be completely removed when HMR isn't enabled.

Bun's bundler treats `import.meta.hot` as a compile-time feature, not a regular JS property. When you use optional chaining (`import.meta.hot?.dispose(...)`), Bun can't statically determine whether to include or exclude the HMR code. By using a direct conditional instead, Bun can see at compile time that the block should be completely removed when HMR isn't enabled.
probablycorey added 1 commit 2026-01-20 18:50:19 +00:00
Use direct conditional instead of optional chaining so Bun can
statically analyze and remove the HMR block in production builds.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
defunkt merged commit 50aa4c5d07 into main 2026-01-21 00:02:47 +00:00
Owner

Oh nice! 🐾

Oh nice! 🐾
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: defunkt/forge#1
No description provided.