web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
10.04k stars 573 forks source link

[Bug]: source code content was incorrectly replaced by file hash name. #8474

Open bigbossx opened 3 days ago

bigbossx commented 3 days ago

System Info

rsbuild version: 1.0.19

// use in project
export const lazyLoadDateHolidays = () => {
  return import(
    /* webpackChunkName: "date-holidays"*/
    /* webpackPrefetch: true */
    'date-holidays'
  );
};

break down in production build

Image

Details

maybe rspack need a better way to replace hash content in chunk, not global replace

please cc @chenjiahan btw, thanks for your quick answer in wechat. help me a lot

Reproduce link

No response

Reproduce Steps

source code was break down in

Image

bigbossx commented 3 days ago

workaround:

// rsbuild.config.ts

export default defineConfig({
   output:{
     filenameHash: 'contenthash:16' // long hash name to reduce the probability of conflict
   }
})
chenjiahan commented 3 days ago

Yes, we have discussed this issue. Using a content hash of 10 characters or more should avoid this problem, but it will also increase the bundle size slightly.

If Rspack can implement a more secure hash replacement, that will be the best approach.

inottn commented 3 days ago

It might be similar to https://github.com/webpack/webpack/issues/14058.

chenjiahan commented 3 days ago

Duplicate with: https://github.com/web-infra-dev/rspack/issues/5339

bigbossx commented 3 days ago

just a suggestion:

  1. maybe we can change the default config in rsbuild to

    const getHash = () => {
    if (typeof filenameHash === 'string') {
      return filenameHash ? `.[${filenameHash}]` : '';
    }
    return filenameHash ? '.[contenthash:12]' : '';
    };
  2. and note this warning or tips in rspack docs

in next release

because it seems like it will take some time to really fix it(webpack too), but before that, we can reduce the probability of bugs happening(we was report by user in production env🥹)