sentry-javascript-bundler-plugins icon indicating copy to clipboard operation
sentry-javascript-bundler-plugins copied to clipboard

[webpack] debugId on main entry file keeps changing due to other chunk

Open vincenthend opened this issue 1 year ago • 2 comments

Environment

@sentry/[email protected]

Steps to Reproduce

  • I have a multiple entry files (main.js, other_entry.js) and few other chunks (foo.js and bar.js). foo.js is uniquely generated per build.
    • other_entry.js is using foo.js
    • main.js is using bar.js
  • Each chunk in the build will be generated with the name [id].[contentHash].js for caching purposes
  • Since foo.js keeps changing on every build, thedebugId generated for main.js is affected
  • The debugId for main.js changed changing the final contentHash and breaking the cache behaviour
  • The debugId for bar.js remains constant

Apparently this happened due to the use of hash for generating debugId

        new BannerPlugin({
          raw: true,
          include: /\.(js|ts|jsx|tsx|mjs|cjs)$/,
          banner: (arg?: BannerPluginCallbackArg) => {
            const debugId = arg?.chunk?.hash ? stringToUUID(arg.chunk.hash) : uuidv4();
            return getDebugIdSnippet(debugId);
          },
        })

Expected Result

  • debugID on main.js should remain constant since the real file content doesn't change

Actual Result

  • debugID for main.js changed although the real content of the file doesn't change.

Suggestion

Probably good if we can have it generated based on contentHash instead of hash

vincenthend avatar Nov 21 '23 10:11 vincenthend

Since foo.js keeps changing on every build, thedebugId generated for main.js is affected

Can you explain why changing foo.js affects the hash of main.js?

But in general you're probably right that we should use the content hash instead.

lforst avatar Nov 21 '23 10:11 lforst

Can you explain why changing foo.js affects the hash of main.js?

Hmm, if I'm debugging it correctly, the cause for my case is due to chunk.hash for entry files seems to be generated using the child compilation

vincenthend avatar Nov 21 '23 10:11 vincenthend

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

getsantry[bot] avatar Nov 23 '24 08:11 getsantry[bot]