Skip to content

fix(compiler): guard webpack HMR dispose data on first module evaluation - #389

Merged
trueadm merged 1 commit into
octanejs:mainfrom
Huxpro:fix/universal-webpack-hmr-first-eval
Jul 29, 2026
Merged

trueadm merged 1 commit into
octanejs:mainfrom
Huxpro:fix/universal-webpack-hmr-first-eval

Conversation

@Huxpro

@Huxpro Huxpro commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Guard hot.data in the universal renderer's webpack-HMR handoff so a module's first evaluation no longer crashes.

Why

  • webpack and rspack leave module.hot.data undefined until a previous instance of the module has disposed. The emitted handoff read hot.data.__octaneUniversalComponents unguarded, so every dev bundle compiled with the webpack HMR dialect threw TypeError: cannot read property '__octaneUniversalComponents' of undefined at module init.
  • Found on a real device: any pluginOctane({ dev: true, hmr: true }) Rspeedy bundle crashed on Lynx Explorer 3.9 (iOS) before rendering. The Vite dialect never hit this because Vite initializes import.meta.hot.data to {}; the DOM webpack dialect already guards through optional member access.

Changes

  • compile-universal.js: hmrHandoffStatements now emits hot.data && hot.data.__octaneUniversalComponents && … instead of dereferencing hot.data directly.
  • universal-renderer.test.ts: new behavioral regression that compiles a webpack-HMR universal module and executes it against a webpack-shaped hot object with data: undefined (throws pre-fix with the exact device error), then replays the dispose bag and asserts the retained component keeps canonical identity.

Validation

  • targeted tests: vitest run packages/octane/tests/universal-renderer.test.ts — 176 passed (octane + octane-prod projects)
  • pre-fix failure confirmed: with the compiler change stashed, the new test fails with TypeError: Cannot read properties of undefined (reading '__octaneUniversalComponents') in both projects
  • prettier --check on changed files
  • full pnpm test / pnpm typecheck not run for this PR (compiler-local change; full lynx-project suite was run on the combined branch during device verification)

Risk / follow-ups

  • Behavior change is limited to generated dev/HMR output; production output is untouched. On update evaluations hot.data is defined and the handoff behaves exactly as before.
  • Verified end-to-end on Lynx Explorer 3.9 (iOS simulator): dev bundles now evaluate and render.

Note

Low Risk
Scoped to dev/HMR codegen in the universal compiler; production bundles are unaffected and hot-update paths behave the same when hot.data is defined.

Overview
Fixes a dev-only crash on the first load of universal modules built with the webpack/rspack HMR dialect: emitted handoff code now checks hot.data exists before reading __octaneUniversalComponents, matching webpack/rspack semantics (dispose bag is undefined until the prior module instance disposes).

Adds a behavioral regression test that compiles a webpack-HMR universal module, evaluates it with data: undefined, then replays dispose and asserts component identity is preserved on hot update. Production output is unchanged; only generated HMR handoff differs.

Reviewed by Cursor Bugbot for commit ad58530. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
octane-website Ready Ready Preview, Comment Jul 29, 2026 7:22pm
octane-website-mcp Ready Ready Preview, Comment Jul 29, 2026 7:22pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 29, 2026 19:21 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 29, 2026 19:22 Inactive
@trueadm
trueadm merged commit 62d81b8 into octanejs:main Jul 29, 2026
3 checks passed

This branch was previously deployed

2 inactive deployments
Preview – octane-website — ad585305 Deployed Jul 29, 2026 by vercel[bot]
Preview – octane-website-mcp — ad585305 Deployed Jul 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants