Skip to content
Source
Sign inSign up
TanStack/router

fix(router-core): detect Webpack/Rspack ChunkLoadError in isModuleNotFoundError #7653

Closedsijie-Z(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/7653/headopened

Closes #7633.

Problem

isModuleNotFoundError() only detects browser-native ESM import errors. When lazy route chunks are bundled by Webpack or Rspack, a failed dynamic import throws ChunkLoadError with message Loading chunk 123 failed.... The auto-reload path in lazyRouteComponent is never triggered.

Solution

Two additions:

  1. Check error.name === "ChunkLoadError"
  2. Check error.message.startsWith("Loading chunk")

Testing

11 tests added covering Chrome, Firefox, Safari, Webpack, Rspack, and edge cases.

    1. Review Change Stack

      Note

      Currently processing new changes in this PR. This may take a few minutes, please wait...

      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: b91383bc-2726-4424-a3f2-5f45129eecb1

      📥 Commits

      Reviewing files that changed from the base of the PR and between ac821f40aa53d387d4b5f9a5fa5e47d9407665bf and 8aa846ef719dbd237e5c0cd3c45b70fb74a7bd5c.

      📒 Files selected for processing (2)
      • packages/router-core/src/utils.ts
      • packages/router-core/tests/is-module-not-found-error.test.ts
       _____________________________________________
      < Nose to the grindstone, eyes on the screen. >
       ---------------------------------------------
        \
         \   \
              \ /\
              ( )
            .( o ).
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands and usage tips.

      Tip

      You can get early access to new features in CodeRabbit.

      Enable the early_access setting to enable early access features such as new models, tools, and more.

    2. Caution

      Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

      Error details
      {}
    3. Superseded by #8277, which builds on this contribution and consolidates the related HMR and missing-chunk recovery fixes. Contributor credit is preserved in the replacement.

Sign in to join this conversation.