You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Injected debug id causing hash differences in cross-architecture builds #15745
Use [contenthash] in place of [chunkhash] for consistent cross-architecture builds
Build docker image for multiple architectures
Note that each build has generated a different debugId, which causes the contenthash to change.
Expected Result
Content hashes should be consistent across architectures. I think we can accomplish this by specifying which hash the debugId uses, I suspect it's using the id/chunkhash and not the contenthash?
Actual Result
Content hashes are different across architectures. Similar to the issue described in #13971
changed the title [-]Injected debug script causing hash differences in cross-architecture builds[/-][+]Injected debug id causing hash differences in cross-architecture builds[/+]on Mar 19, 2025
Afaik, debug ids are generated based on code, hashes are stripped from the file endings. Are you observing consistent hashes without Sentry?
Yes, hashes are consistent between architectures when not using the sentry plugin (caveat: I replace [chunkhash] with [contenthash] as the arm/amd builds were generating different chunkhashes):
I also went into the differently hashed files (in this case it was only _app-*.js) and confirmed that when the sentry debug injected code was removed, the files hashed identically and had no diff.
ARM (Sentry)
├ chunks/pages/_app-40949006ebec3ca7.js 865 kB
AMD (Sentry)
├ chunks/pages/_app-bc03ec9e4895a4b6.js 865 kB
Looking at the logs, I suspect that sentry is injecting the code before nextjs has calculated the hashes and output the files, so when nextjs calculates the contenthash they are different. As to why the uuid is different between the two architectures for the same file contents, I'm not sure. I need to dig into the intermediary steps more.
It's my understanding that hash is generated per-build so because we have to build on each architecture, we have two builds, and therefore two hashes. Either that or the hash differs because of the architecture itself. I think this explains why the uuid differs between the two architectures, and a possible fix is to use contenthash and not hash from the chunk.
As a workaround I wrote a plugin to patch the BannerPlugin added by sentry to look at contentHash instead of hash. Now my build artifacts match across architectures.
@andreiborza I don't think an option is necessary. I don't think hash is different for every build, but we can just default to contentHash and fall back to hash.
You're right actually, I just tested without the sentry plugin at all (and reverting my contenthash to chunkhash) and the file hashes are identical. So something else might be going on here...
Good callout @lforst thanks. I looked deeper at the build logs and tried different configurations. With sentry plugin added, it seems like the chunk hash can differ between the builds when they are processed in a different order. No idea why this doesn't occur when the sentry plugin is removed.
Note the content hashes are identical, and even the id's are identical, but the chunk hashes are different, but only for this _app file. The chunk hash of the other file whose processing order changed (_error) is the same. I'm kinda stumped here. Looking at the files, they are identical and the only difference ends up being the injected sentryDebugId.
Nevertheless, using contenthash instead of chunkhash does seem to resolve all my issues. So... 🤷
Activity
[-]Injected debug script causing hash differences in cross-architecture builds[/-][+]Injected debug id causing hash differences in cross-architecture builds[/+]andreiborza commentedon Mar 20, 2025
Hi @Redmega, thanks for filing this.
Afaik, debug ids are generated based on code, hashes are stripped from the file endings. Are you observing consistent hashes without Sentry?
cc @lforst
lforst commentedon Mar 20, 2025
What are you using to inject debug IDs? The CLI? If so, it should inject a deterministic uuid based on file-content.
Redmega commentedon Mar 20, 2025
Sorry, not sure why I had
@sentry/browserin the opening comment, I'm using@sentry/nextjs. I must have overlooked that.We also use
nxand this is how my config ends up looking with plugin composition:Yes, hashes are consistent between architectures when not using the sentry plugin (caveat: I replace
[chunkhash]with[contenthash]as the arm/amd builds were generating different chunkhashes):ARM (No Sentry)
AMD (No Sentry)
I also went into the differently hashed files (in this case it was only
_app-*.js) and confirmed that when the sentry debug injected code was removed, the files hashed identically and had no diff.ARM (Sentry)
AMD (Sentry)
Looking at the logs, I suspect that sentry is injecting the code before nextjs has calculated the hashes and output the files, so when nextjs calculates the contenthash they are different. As to why the uuid is different between the two architectures for the same file contents, I'm not sure. I need to dig into the intermediary steps more.
Redmega commentedon Mar 20, 2025
Actually, in the webpack plugin which is what the nextjs plugin uses under the hood I believe?
hashis used instead ofcontenthash.It's my understanding that
hashis generated per-build so because we have to build on each architecture, we have two builds, and therefore two hashes. Either that or the hash differs because of the architecture itself. I think this explains why the uuid differs between the two architectures, and a possible fix is to usecontenthashand nothashfrom the chunk.Redmega commentedon Mar 20, 2025
As a workaround I wrote a plugin to patch the BannerPlugin added by sentry to look at contentHash instead of hash. Now my build artifacts match across architectures.
I think an option to use the content hash instead of the chunk hash would be ideal for usecases like this.
andreiborza commentedon Mar 21, 2025
Ah, great find. Making this configurable for webpack sounds reasonable to me, wdyt @lforst?
lforst commentedon Mar 21, 2025
@andreiborza I don't think an option is necessary. I don't think hash is different for every build, but we can just default to contentHash and fall back to hash.
Redmega commentedon Mar 21, 2025
You're right actually, I just tested without the sentry plugin at all (and reverting my
contenthashtochunkhash) and the file hashes are identical. So something else might be going on here...Redmega commentedon Mar 21, 2025
Good callout @lforst thanks. I looked deeper at the build logs and tried different configurations. With sentry plugin added, it seems like the chunk hash can differ between the builds when they are processed in a different order. No idea why this doesn't occur when the sentry plugin is removed.
AMD
ARM
Note the content hashes are identical, and even the
id's are identical, but the chunk hashes are different, but only for this_appfile. The chunk hash of the other file whose processing order changed (_error) is the same. I'm kinda stumped here. Looking at the files, they are identical and the only difference ends up being the injected sentryDebugId.Nevertheless, using contenthash instead of chunkhash does seem to resolve all my issues. So... 🤷
lforst commentedon Mar 24, 2025
Thanks for the followup! We'll just default to contentHash and use chunk.hash if that's not available.