Skip to content

feat: allow to modify provider options within props#2101

Open
huang-julien wants to merge 3 commits intomainfrom
feat/option_attribute
Open

feat: allow to modify provider options within props#2101
huang-julien wants to merge 3 commits intomainfrom
feat/option_attribute

Conversation

@huang-julien
Copy link
Member

@huang-julien huang-julien commented Jan 31, 2026

🔗 Linked issue

❓ Type of change

related to #2100

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

When working on #2100 . I noticed that accountHash shouldn't be in modifiers, and should be something easily modifiable at runtime (users can have multiple providers)

this PR allows to send new options thorugh nuxtImg and nuxtPicture props with options attribute. It also allows to have { baseUrl } configurable when a component renders.

Small example of what could be possible

    <nuxt-img
     v-for="img in storedImages"
      :provider="img.provider"
      :src="img.src"
      :options="{
        baseURL: img.baseURL
      }"
      width="500"
      height="500"
    />

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 31, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/image@2101

commit: 54df2c4

@coderabbitai
Copy link

coderabbitai bot commented Jan 31, 2026

📝 Walkthrough

Walkthrough

An optional options property was added to BaseImageProps<Provider> in src/runtime/utils/props.ts, typed as ConfiguredImageProviders[Provider]. The useImageProps logic now merges props.options into providerOptions via object spread. Separately, ImageModifiers.blur in src/types/image.ts was widened from number to number | string, and this change propagates to resolved modifier types.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: allowing provider options to be modified through component props, which is the core objective of this PR.
Description check ✅ Passed The description is well-related to the changeset, explaining the motivation (accountHash runtime configurability), the solution (options prop), and providing a concrete usage example.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/option_attribute

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/runtime/utils/props.ts`:
- Around line 41-45: The computed providerOptions merges props in the wrong
order so props.options can override explicit props.provider and props.preset;
change the merge order in the providerOptions computed so props.options is
spread first and then provider: props.provider and preset: props.preset are
added (i.e., ensure explicit keys in providerOptions take precedence over keys
from props.options), updating the computed that builds providerOptions
accordingly and add a comment if the override behavior is intentional.
- Around line 23-24: The type for options is too broad and the spread order is
reversed: change the type of props.options from
ConfiguredImageProviders[Provider] to the narrower ImageOptions (or create a
dedicated RuntimeImageOptions type containing only provider, preset, densities,
modifiers, sizes) so it matches what ImageOptions expects, and update the object
construction so you spread props.options first and then explicitly set provider
and preset (or keep explicit values last) to ensure explicit props cannot be
overridden by props.options; reference the symbols options,
ConfiguredImageProviders, ImageOptions, props.options, provider, preset,
densities, modifiers, sizes in your change.

Comment on lines +23 to +24
options?: ConfiguredImageProviders[Provider]

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's read the file to understand the full context
cat -n src/runtime/utils/props.ts

Repository: nuxt/image

Length of output: 2435


🏁 Script executed:

# Search for ConfiguredImageProviders definition and augmentation patterns
rg -n 'ConfiguredImageProviders' --type=ts -B 2 -A 5 | head -100

Repository: nuxt/image

Length of output: 5532


🏁 Script executed:

# Search for how providers augment ConfiguredImageProviders
rg -n 'declare module.*ConfiguredImageProviders' --type=ts -A 5 | head -50

Repository: nuxt/image

Length of output: 36


🏁 Script executed:

# Look for provider implementations to understand ConfiguredImageProviders structure
find src -name "*.ts" -type f | xargs grep -l "ImageProviders\|ConfiguredImageProviders" | head -10

Repository: nuxt/image

Length of output: 185


🏁 Script executed:

# Check index.d.ts
cat -n src/index.d.ts

echo "---"

# Look for provider directories with examples
ls -la src/providers/ 2>/dev/null | head -20

Repository: nuxt/image

Length of output: 735


🏁 Script executed:

# Check the ipx provider to understand the options structure
cat -n src/runtime/providers/ipx.ts | head -80

Repository: nuxt/image

Length of output: 3066


🏁 Script executed:

# Search for useImageProps usage
rg -n 'useImageProps' --type=ts -B 2 -A 5 | head -80

Repository: nuxt/image

Length of output: 540


🏁 Script executed:

# Search for imports and usages of useImageProps
rg -n 'import.*useImageProps' --type=ts -B 2 -A 5

Repository: nuxt/image

Length of output: 36


🏁 Script executed:

# Check what's exported from props.ts
rg -n 'export' src/runtime/utils/props.ts

echo "---"

# Look for test files that might show usage
find . -name "*.test.*" -o -name "*.spec.*" | grep -i props | head -10

Repository: nuxt/image

Length of output: 262


🏁 Script executed:

# Look for any component or test files that use BaseImageProps
find . -type f \( -name "*.vue" -o -name "*.test.ts" -o -name "*.spec.ts" \) -exec grep -l "BaseImageProps\|useImageProps" {} \;

Repository: nuxt/image

Length of output: 131


🏁 Script executed:

# Check how NuxtImg.vue uses BaseImageProps and options
cat -n src/runtime/components/NuxtImg.vue | head -150

Repository: nuxt/image

Length of output: 5317


🏁 Script executed:

# Look at the getSizes method signature
rg -n 'getSizes' src/runtime/image.ts -A 10 | head -60

Repository: nuxt/image

Length of output: 2400


🏁 Script executed:

# Check the $img function signature - what does it expect as the third parameter?
rg -n 'function.*\$img|export.*\$img' src/runtime/image.ts -A 5 | head -40

Repository: nuxt/image

Length of output: 36


🏁 Script executed:

# Look at the createImage function and its return value
cat -n src/runtime/image.ts | sed -n '8,110p'

Repository: nuxt/image

Length of output: 4065


🏁 Script executed:

# Look at resolveImage to see which options are actually used
cat -n src/runtime/image.ts | sed -n '52,107p'

Repository: nuxt/image

Length of output: 2225


🏁 Script executed:

# Let's check the ImageOptions interface more carefully to see what properties it expects
cat -n src/types/image.ts | sed -n '20,35p'

Repository: nuxt/image

Length of output: 1029


Verify the type and fix the spread order for options.

The type ConfiguredImageProviders[Provider] represents the entire provider configuration, but ImageOptions expects only specific properties (provider, preset, densities, modifiers, sizes). Using the full provider config as the type is too broad.

Additionally, at line 44, spreading props.options after explicitly setting provider and preset is backwards—if props.options contains these keys, they override the explicit props. The spread should come first, or better, the options type should be narrowed to only the expected runtime options.

🤖 Prompt for AI Agents
In `@src/runtime/utils/props.ts` around lines 23 - 24, The type for options is too
broad and the spread order is reversed: change the type of props.options from
ConfiguredImageProviders[Provider] to the narrower ImageOptions (or create a
dedicated RuntimeImageOptions type containing only provider, preset, densities,
modifiers, sizes) so it matches what ImageOptions expects, and update the object
construction so you spread props.options first and then explicitly set provider
and preset (or keep explicit values last) to ensure explicit props cannot be
overridden by props.options; reference the symbols options,
ConfiguredImageProviders, ImageOptions, props.options, provider, preset,
densities, modifiers, sizes in your change.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 31, 2026

Deploying nuxt-image with  Cloudflare Pages  Cloudflare Pages

Latest commit: 54df2c4
Status: ✅  Deploy successful!
Preview URL: https://82a64895.nuxt-image.pages.dev
Branch Preview URL: https://feat-option-attribute.nuxt-image.pages.dev

View logs

@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 6.99%. Comparing base (ac802b3) to head (54df2c4).

Files with missing lines Patch % Lines
src/runtime/utils/props.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main   #2101   +/-   ##
=====================================
  Coverage   6.99%   6.99%           
=====================================
  Files         78      78           
  Lines       3632    3631    -1     
  Branches     140     140           
=====================================
  Hits         254     254           
+ Misses      3329    3328    -1     
  Partials      49      49           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants