Skip to content

Data prefetch bundle is fetched *after* remote component execution instead of in parallel #3858

@PezCoder

Description

@PezCoder

Describe the bug

What?

Hey! We recently integrated MFE via module federation in my org & we're currently working on optimising the performance for the same.

Data prefetch seemed like a great action item for the same & I've gone through the following doc:
https://module-federation.io/practice/performance/prefetch.html

My takeaway from the doc was that, the prefetch should happens 'alongside' the bundles being fetched. For example, if I have a Header component which is exposed from a remote named Home I would expect that the Header.prefetch.js should be called & executed in 'parallel' to fetching the Header bundle itself.

But I noticed the behaviour to be on the contrary, whereas it:

  • Initially downloads the Header component from remote
  • Starts parsing & rendering it & realises there is a usePrefetch
  • At this point is when it further pulls in the prefetch bundle Header.prefetch.js & further executes it
  • & Header is re-rendered further when the data is resolved

Expected behaviour
My expectations was that, the Header prefetch API to be called alongside Header bundle fetching itself, that's where the true gain lies in performance. Otherwise, this is no different then making a call itself within an effect within Header.

Screenshots

Header Header
Image Calling the API as part of the use effect, triggers the API call after the bundles are fetched & executed
Image Using data prefetch to fetch data for Header instead, has a similar graph ⚠
Image Notice the order of execution for Header & Header prefetch

⚠ Notice how the bootstrap file is fetched at much later point after the Header component itself is parsed.

Reproducible example

https://github.com/PezCoder/micro-frontend-prefetch-example

Question: I understand that we're not using react-router, defer, async please let me know if they're necessary for something like that to work, or if my expectation is incorrect on the behaviour of prefetch itself.

Reproduce sample repository

https://github.com/PezCoder/micro-frontend-prefetch-example

Used Package Manager

yarn

System Info

System:
    OS: macOS 14.7.6
    CPU: (12) arm64 Apple M3 Pro
    Memory: 332.30 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.18.1 - ~/.nvm/versions/node/v20.18.1/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.18.1/bin/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v20.18.1/bin/npm
    Watchman: 2025.04.28.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 137.0.7151.120
    Edge: 137.0.3296.93
    Safari: 17.6

Validations

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions