Skip to content

[Bug]: Child HMR not working when parent component has HMR #11635

Closed as not planned
Closed as not planned

Description

@yuhengshen

Version

System:
    OS: Linux 6.6 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (6) x64 Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
    Memory: 13.55 GB / 15.59 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  npmPackages:
    @rsbuild/core: ^1.5.4 => 1.5.6 
    @rsbuild/plugin-vue2: ^1.0.4 => 1.0.4

Details

  1. ​​trigger the parent component's HMR.​
  2. changing the child component, HMR is not working.

Reproduce link

yuhengshen/rsbuild-test-hmr

Reproduce Steps

Activity

  1. added theissue type on Sep 10, 2025
  2. added theissue type on Sep 10, 2025
  3. ShunquanWang commented on Sep 11, 2025

    @ShunquanWang

    I encountered the same problem

  4. ShunquanWang commented on Oct 14, 2025

    @ShunquanWang

    When will this problem be fixed? @stormslowly

  5. stormslowly commented on Nov 28, 2025

    @stormslowly
    Contributor

    @tclxshunquan-wang @yuhengshen
    I had dome some studies about your reproduction, but I didn't get much clue about the root cause due to i don't know much about Vue and it's compilation.

    Since Vue2 is end of life more than 1 year and We don't have much bandwidth to deal Vue2's case.

    And Rsbuild has a builtin Vue3 plugin, could plz have a try with that by upgrading to Vue3?

  6. yuhengshen commented on Dec 1, 2025

    @yuhengshen
    Author

    I checked it some time ago. When the hot update fails, the pulled HMR hash key is old rather than the latest one.
    It might be a bug caused by the cache system.

  7. stormslowly commented on May 19, 2026

    @stormslowly
    Contributor

    Hi @yuhengshen @tclxshunquan-wang,

    Going to close with a workaround. Quick rundown:

    Root cause

    flowchart TD
      edit["Edit Child.vue <template>"] --> rebuild["Both sub-modules rebuilt"]
      rebuild --> bytes["script-setup emitted bytes<br/>UNCHANGED"]
      rebuild --> map["script-setup source map<br/>sourcesContent[0] = whole Child.vue<br/>CHANGED"]
      bytes --> hash
      map --> hash["SourceMapSource.hash<br/>folds sourcesContent into digest"]
      hash --> emit["HMR ships byte-identical<br/>script-setup in hot-update.js"]
      emit --> bubble["No accept handler →<br/>bubbles to SFC main wrapper"]
      bubble --> reload["api.reload (not api.rerender)"]
      reload --> drift["After parent HMR, record.Ctor<br/>≠ live instance Ctor"]
      drift --> dom["instance.$options.render stays stale<br/>→ DOM not updated"]
      style map fill:#ffe6e6
      style hash fill:#ffe6e6
      style dom fill:#ffcccc
    
    Loading

    vue-loader's SFC sub-modules each carry a SourceMapSource whose source map embeds the whole Child.vue as sourcesContent[0]. Hashing the source map alongside the emitted bytes means any template edit flips the codegen hash of every sibling sub-module — even when their bytes are stable.

    Same bug in webpack

    bundler dev devtool hot-update emits child HMR
    webpack eval (default) template only ✓
    webpack cheap-module-source-map template + script-setup ✗
    rspack eval (override) template only ✓
    rspack cheap-module-source-map (default) template + script-setup ✗

    webpack only escapes by default because devtool: 'eval' doesn't produce a SourceMapSource. rspack defaults to cheap-module-source-map, so the bug shows up immediately.

    Workaround

    // rsbuild.config.ts
    export default defineConfig({
      plugins: [pluginVue2()],
      tools: { rspack: { devtool: 'eval' } },
    });

    Why not patch

    I drafted a fix at #14046 but decided not to land it: Vue 2 is EOL, the bug is shared with webpack under the same devtool, and the one-line config workaround is fine for the small remaining Vue 2 user base.

    If you can move to Vue 3, the new __VUE_HMR_RUNTIME__ rerender path sidesteps the record.Ctor drift entirely.

    Closing as wontfix with workaround. Thanks for the reproduction!

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions