-
-
Notifications
You must be signed in to change notification settings - Fork 366
Description
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
⚠ 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
- Read the docs.
- Read the common issues list.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Module federation issue and not a framework-specific issue.
- The provided reproduction is a minimal reproducible example of the bug.