core icon indicating copy to clipboard operation
core copied to clipboard

federation runtime vue 3 remotes with getPublicPath generates double calls (one with wrong public path)

Open WeetA34 opened this issue 1 year ago • 17 comments

Describe the bug

Hello,

I use federation runtime to dynamically import vue 3 remotes with getPublicPath. some css, vendors assets are called twice:

  • once with the proper public path retrieved through the getPublicPath function
  • once with the consumer url which returns in my case the root html.

you can see screenshots in the repro project README.

It doesn't always generate an issue as one of the two calls succeeds.

I don't have this behavior if I replace getPublicPath by a static publicPath.

Thank you

Reproduction

https://github.com/WeetA34/mf-double-calls-repro

Used Package Manager

yarn

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 128.44 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.1 - /usr/local/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn ---> yarn 4.3.1 with nodeLinker node-modules in the project
    npm: 9.8.1 - /opt/homebrew/bin/npm
    pnpm: 9.4.0 - /opt/homebrew/bin/pnpm
    bun: 1.0.21 - ~/.bun/bin/bun
  Browsers:
    Chrome: 126.0.6478.185
    Safari: 17.5

Validations

WeetA34 avatar Jul 30 '24 09:07 WeetA34

Hello, fyi, it's still the same with 0.3.5

WeetA34 avatar Aug 09 '24 10:08 WeetA34

Hello, fyi, it's still the same with 0.5.1

WeetA34 avatar Aug 21 '24 17:08 WeetA34

Hello, fyi, it's still the same with 0.6.3 :)

WeetA34 avatar Sep 13 '24 14:09 WeetA34

+1, seeing the same issue as well (with React, although that doesn't really matter here)

TSMI235 avatar Sep 18 '24 19:09 TSMI235

Hello, fyi, it's still the same with 0.6.8 :)

WeetA34 avatar Oct 02 '24 08:10 WeetA34

hmm seems like a legit issue. Will check the source code. You can try setting public path to auto?

ScriptedAlchemy avatar Oct 10 '24 21:10 ScriptedAlchemy

Hello Zack, i'll test that. thx

WeetA34 avatar Oct 12 '24 12:10 WeetA34

Hello Zack, It seems to be ok without getPublicPath and config.output.publicPath set to 'auto' instead. Thank you

WeetA34 avatar Oct 17 '24 09:10 WeetA34

Hello again, I moved to @module-federation/rsbuild-plugin. publicPath='auto' by default It works fine

WeetA34 avatar Oct 17 '24 09:10 WeetA34

Perfect

ScriptedAlchemy avatar Oct 17 '24 13:10 ScriptedAlchemy

Stale issue message

github-actions[bot] avatar Dec 16 '24 15:12 github-actions[bot]

Bump

ScriptedAlchemy avatar Dec 18 '24 03:12 ScriptedAlchemy

The wrong css asset is loaded by producer's miniCss runtime . It will use publicPath + assetUrl as final url .

And the producer not set specific publicPath , so it will call twice .

2heal1 avatar Dec 18 '24 09:12 2heal1

I am having the exact issue as the original poster describes, but when using RsBuild.

I used the workaround mentioned of setting config.output.publicPath, but I am setting it to a specific URL (not 'auto') and it builds the mf-manifest.json with publicPath: '/' which is not what I expect. Does config.output.publicPath not work with RsBuild?

ghost avatar Feb 14 '25 05:02 ghost

Check docs. Rsbuild sets it a different way than rspack. Assetprefix or something

ScriptedAlchemy avatar Mar 15 '25 22:03 ScriptedAlchemy

Thanks @ScriptedAlchemy, I found someone had mentioned assetPrefix in another issue and that does indeed work for rsbuild.

Just an FYI to others using rsbuild that come across this page, when using 'output.assetPrefix' you don't need to use 'getPublicPath', as 'publicPath' in the mf-manifest.json will be populated with the assetPrefix value from what I observed.

ghost avatar Mar 15 '25 23:03 ghost

I'll look at adding schema validation to rsbuild so people don't get confused

ScriptedAlchemy avatar Mar 16 '25 01:03 ScriptedAlchemy

Stale issue message

github-actions[bot] avatar May 15 '25 15:05 github-actions[bot]