fix(handlers): parse all modulate args and add lightness - #317
Merged
Conversation
`modulate` declared `args: [VArg]`, so `parseArgs` only ever mapped the
first URL segment and `saturation`/`hue` reached sharp as `undefined`.
Sharp validates with `key in options` rather than a defined-check, so the
`undefined` values still tripped validation and *every* `modulate_*` URL
failed with:
[IPX_ERROR] Expected number above zero for saturation but received
undefined of type undefined
Declare all four mappers, add sharp's `lightness` option, and omit args
that were not supplied from the options object so trailing arguments stay
optional.
Covered by unit tests that go through `applyHandler` (the arg-count
contract, which a direct `apply()` call cannot exercise) and by an
end-to-end test over every arity against real sharp — mocking sharp is
what hid the `key in options` behaviour in the first place.
Resolves #301
Resolves nuxt/image#1968
Closes #294
Closes #312
Co-authored-by: Damian Głowala <48835293+DamianGlowala@users.noreply.github.com>
Co-authored-by: Devanshu Biswas <40787559+dev48v@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe ChangesModulate support
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
pi0
approved these changes
Jul 26, 2026
This was referenced Jul 26, 2026
This was referenced Jul 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #294 and #312, which both target #301 and touch the same lines. Combines the fix from each and closes a gap neither caught.
The bug
modulatedeclaredargs: [VArg], soparseArgsonly ever mapped the first URL segment —saturationandhuereached sharp asundefined.The part that isn't obvious: sharp validates with
'key' in options, not a defined-check (operation.mjs). Because the handler always spread all keys into the object, theundefinedvalues were still present and tripped validation. Somodulateis currently broken for every input onmain, not just multi-arg ones:Measured against
test/assets/bliss.jpg:mainmodulate_2modulate_2_1modulate_2_1_90modulate_2_1_90_10Worth noting #294 as it stands regresses
modulate_2_1_90— addinglightnessintroduces a fourth always-present key. Its unit test passes only because sharp is mocked.The fix
parseArgsreaches every segment.lightnessoption (from fix: addlightnessarg to modulate modifier #294).Tests
applyHandler(from fix(handlers): parse all three modulate args (brightness, saturation, hue) #312's approach) — a directapply()call can't exercise the arg-count contract, which is why the original bug survived a green suite.key in optionsbehaviour, so at least one test has to hit the real pipeline.eslint,prettier -c src testandvitest runall pass. One unrelated pre-existing failure remains on this branch and onmain:test/index.test.ts > remote filefails withserveStatic is not a functionafter the recent srvx bump.Credit to @DamianGlowala and @dev48v — this is their work combined.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
modulateimage adjustments.Documentation
modulateformat.Bug Fixes