module-federation / core

Module Federation is a concept that allows developers to share code and resources across multiple JavaScript applications
https://module-federation.io/
MIT License
1.49k stars 226 forks source link

Unable to fetch updated remote module code (caching issue?) #3119

Open arimus opened 1 day ago

arimus commented 1 day ago

Describe the bug

I have a host and a remote. The initial init + fetch works great, when a changes is made to the remote that host detects it with revalidate(), but a subsequent init + fetch seems to get the old code still.

Host: built with webpack, dynamic loading of module, using revalidate() to poll for changes that require an init + reload Remote: running with webpack dev server

I'm not sure how to ensure the latest version of the code is fetched / the appropriate caches are cleared / etc.

p.s. is there no way for the host to get the HMR updates and trigger a reload off of that instead of polling or is the lack of a browser environment a deal breaker atm?

Reproduction

https://github.com/arimus/dynamic-remotes-node

Used Package Manager

npm

System Info

System:
    OS: macOS 14.4
    CPU: (10) x64 Apple M1 Pro
    Memory: 14.80 MB / 16.00 GB
    Shell: 5.2.21 - /opt/homebrew/bin/bash
  Binaries:
    Node: 20.12.0 - ~/.nvm/versions/node/v20.12.0/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.0/bin/npm
    pnpm: 9.11.0 - ~/Library/pnpm/pnpm
    Watchman: 2024.08.05.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 130.0.6723.60
    Chrome Canary: 132.0.6795.0
    Edge: 130.0.2849.52
    Safari: 17.4
    Safari Technology Preview: 17.4

Validations

2heal1 commented 18 hours ago

Oh... i know the reason . Because runtime will catch the loaded remoteEntry/manifest in __GLOBAL_LOADING_REMOTE_ENTRY__ . And this attr not be cleared , okay I will expose clearRuntimeCache methods to revalidate

arimus commented 11 hours ago

Just an FYI that this doesn't seems to be the case at first glance. I am dumping the GLOBAL_LOADING_REMOTE_ENTRY and it seems to be empty before and after an init() + loadRemote().

Also, tried a performReload() and that didn't seem to do help either. It has the logic in there to clear GLOBAL_LOADING_REMOTE_ENTRY as well a clear the module cache.