Skip to content

Validate minimum hash length for entry/chunk filenames#7476

Closed
Copilot wants to merge 7 commits intomainfrom
copilot/fix-hash-length-validation
Closed

Validate minimum hash length for entry/chunk filenames#7476
Copilot wants to merge 7 commits intomainfrom
copilot/fix-hash-length-validation

Conversation

Copy link
Contributor

Copilot AI commented Dec 12, 2025

Rolldown was silently clamping hash lengths below 6 to 6 characters for entryFileNames and chunkFileNames. Rollup throws an error instead. The minimum of 6 is required by the internal hash placeholder format !~{xxx}~.

Changes

  • Add validation in FilenameTemplate::render() that errors when hash length < 6 for entryFileNames, chunkFileNames, cssEntryFileNames, cssChunkFileNames
  • Add extract_hash_lengths() to parse [hash:N] patterns
  • Add validate_hash_lengths() to check against minimum
  • Handle malformed patterns correctly (e.g., [hash:abc], [hashmap])
  • Asset filenames remain unrestricted (no placeholder limitation)

Error behavior

// Before: silently generates 6-character hash
output: {
  entryFileNames: '[name]-[hash:2].js'
}

// After: throws error
// Error: Hashes in "entryFileNames" must be at least 6 characters, received 2.

Test updates

  • Update existing test to use [hash:6] instead of [hash:2]
  • Add error test case for hash length validation
Original prompt

This section details on the original issue you should resolve

<issue_title>Error or warn when the hash length is below the minimum hash length</issue_title>
<issue_description>> Hmm but I just did that repro above 15 minutes ago, and I just verified I have the latest published version of rolldown-vite (6.3.0-beta.5). But if it's fixed for next release I have no trouble waiting! 🙏🏼

(BTW when I was trying to repro earlier, another problem I saw was that [hash:2] becomes 6 characters, same for [hash:3], [hash:4], [hash:5]... seems there's a minimum of 6?)

Originally posted by @blixt in #4017</issue_description>

<agent_instructions>entryFileNames and chunkFileNames limits the minimum length to 6 because of the way Rollup / Rolldown handles the hash in the filename. Rollup / Rolldown uses a hash placeholder until the hash is determined (as the hash is determined by the file content, the filename has to be replaced with a placeholder to be contained in the file itself). This hash placeholder looks like !{1} and that requires the minimum length of 6.

Because of the technical limitation above, I think it's not possible to reduce the hash length for entryFileNames and chunkFileNames. The minimum hash length is inconsistent between entryFileNames/chunkFileNames and assetFileNames, but I think that's fine because there's no reason to limit that. But I think we need to error when the length is shorter than the minimum length, or emit a warning if we still want to increase the length automatically. While warning might be slightly better as the user can still build, I think an error is also fine as it aligns the behavior with Rollup. I think we can choose the one easier to implement.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@shulaoda > So the current logic is not internally consistent, and probably asset naming should have a minimum of 6 as well until a decision is made whether or not to support shorter hashes overall.

Yes, but I guess this behavior aligns with rollup.</comment_new>
<comment_new>@sapphi-red
Rollup throws an error when using [hash:2] in entryFileNames or chunkFileNames (stackblitz).
Currently, Rolldown converts [hash:2] to [hash:6] automatically (stackblitz).

Related: rollup/rollup#6098

@sapphi-red `entryFileNames` and `chunkFileNames` limits the minimum length to 6 because of the way Rollup / Rolldown handles the hash in the filename. Rollup / Rolldown uses a hash placeholder until the hash is determined (as the hash is determined by the file content, the filename has to be replaced with a placeholder to be contained in the file itself). This hash placeholder looks like `!~{1}~` and that requires the minimum length of 6.

Because of the technical limitation above, I think it's not possible to reduce the hash length for entryFileNames and chunkFileNames. The minimum hash length is inconsistent between entryFileNames/chunkFileNames and assetFileNames, but I think that's fine because there's no reason to limit that. But I think we need to error when the length is shorter than the minimum length, or emit a warning if we still want to increase the length automatically. While warning might be slightly better as the user can still build, I think an error is also fine as it aligns the behavior with Rollup. I think we can choose the one easier to implement.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@netlify
Copy link

netlify bot commented Dec 12, 2025

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 110e432
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/693be1eb6047a90008aa4552

Copilot AI and others added 6 commits December 12, 2025 09:19
Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error or warning for minimum hash length Validate minimum hash length for entry/chunk filenames Dec 12, 2025
Copilot AI requested a review from shulaoda December 12, 2025 09:38
@github-actions
Copy link
Contributor

Benchmarks Rust

  • target: main(41b396c)
  • pr: copilot/fix-hash-length-validation(110e432)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.03     64.6±1.56ms        ? ?/sec    1.00     62.5±1.53ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.04     71.2±2.16ms        ? ?/sec    1.00     68.1±1.24ms        ? ?/sec
bundle/bundle@rome_ts                                        1.02    108.3±1.63ms        ? ?/sec    1.00    106.6±3.30ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.02    120.6±1.99ms        ? ?/sec    1.00    118.0±1.46ms        ? ?/sec
bundle/bundle@threejs                                        1.00     38.9±0.59ms        ? ?/sec    1.02     39.8±2.45ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.00     42.8±0.99ms        ? ?/sec    1.00     42.8±0.63ms        ? ?/sec
bundle/bundle@threejs10x                                     1.01    392.7±4.01ms        ? ?/sec    1.00    390.4±6.90ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.01    452.2±3.26ms        ? ?/sec    1.00    448.7±4.24ms        ? ?/sec
scan/scan@rome_ts                                            1.00     83.7±2.53ms        ? ?/sec    1.01     84.6±2.22ms        ? ?/sec
scan/scan@threejs                                            1.00     28.2±1.34ms        ? ?/sec    1.03     29.0±1.83ms        ? ?/sec
scan/scan@threejs10x                                         1.00    290.0±3.69ms        ? ?/sec    1.02    296.4±3.76ms        ? ?/sec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error or warn when the hash length is below the minimum hash length

2 participants