-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix(nuxt): prevent Infinity backgroundSize in loading indicator #33211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
WalkthroughA single file, Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks (5 passed)✅ Passed checks (5 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing touches
🧪 Generate unit tests
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
packages/nuxt/src/app/components/nuxt-loading-indicator.ts (3)
37-40: Type props with PropType instead of Function cast.Avoids unsafe casts and improves DX.
- estimatedProgress: { - type: Function as unknown as () => ( - duration: number, - elapsed: number - ) => number, + estimatedProgress: { + type: Function as PropType<(duration: number, elapsed: number) => number>, required: false, },Add this import:
import type { PropType } from 'vue'
77-80: Guard against booleantrueleaking into CSSbackground.If
coloristrue,props.color || undefinedcan pass a truthy non-string. Coerce to string or omit.- background: error.value - ? props.errorColor - : props.color || undefined, + background: error.value + ? props.errorColor + : (typeof props.color === 'string' ? props.color : undefined),
85-85: Micro-optimisation: hint paint pipeline.Add
will-changeto smooth animations on some browsers.transition: 'transform 0.1s, height 0.4s, opacity 0.4s', + willChange: 'transform, opacity',
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/nuxt/src/app/components/nuxt-loading-indicator.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Follow standard TypeScript conventions and best practices
Files:
packages/nuxt/src/app/components/nuxt-loading-indicator.ts
🧬 Code graph analysis (1)
packages/nuxt/src/app/components/nuxt-loading-indicator.ts (1)
packages/nuxt/src/app/composables/loading-indicator.ts (1)
useLoadingIndicator(170-188)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
- GitHub Check: test-fixtures (windows-latest, built, vite, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, rspack, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (windows-latest, built, webpack, async, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, webpack, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (windows-latest, built, vite, async, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, rspack, async, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, webpack, async, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, js, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-off, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-off, json, lts/-1)
- GitHub Check: test-size
- GitHub Check: typecheck (ubuntu-latest, bundler)
- GitHub Check: typecheck (windows-latest, bundler)
- GitHub Check: test-benchmark
- GitHub Check: code
🔇 Additional comments (4)
packages/nuxt/src/app/components/nuxt-loading-indicator.ts (4)
29-30: Readable default gradient — LGTM.Pure formatting; improves readability without behaviour change.
45-52: Options passthrough — LGTM.The composable receives the correct props; no behaviour change.
55-60: Expose shape — LGTM.Public surface matches the composable API.
80-82: Division-by-zero guard — LGTM.Prevents
Infinity%CSS at 0 progress as intended.
| backgroundSize: `${ | ||
| progress.value > 0 ? (100 / progress.value) * 100 : 0 | ||
| }% auto`, | ||
| transform: `scaleX(${progress.value}%)`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix transform: scaleX expects a unitless factor, not a percentage.
Using % yields invalid CSS. Also clamp and handle non-finite values.
- transform: `scaleX(${progress.value}%)`,
+ transform: `scaleX(${Number.isFinite(progress.value) ? Math.max(0, Math.min(1, progress.value / 100)) : 0})`,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| transform: `scaleX(${progress.value}%)`, | |
| transform: `scaleX(${Number.isFinite(progress.value) ? Math.max(0, Math.min(1, progress.value / 100)) : 0})`, |
🤖 Prompt for AI Agents
In packages/nuxt/src/app/components/nuxt-loading-indicator.ts around line 83,
the transform uses `scaleX(${progress.value}%)` which is invalid because scaleX
expects a unitless factor; clamp progress to a finite number between 0 and 1
(e.g. coerce with Number(), handle NaN/Infinity to 0, then use
Math.min(Math.max(value, 0), 1)) and use that clamped value directly in the
scaleX() call without a '%' sign so the style becomes `transform:
\`scaleX(${clamped})\``.
CodSpeed Performance ReportMerging #33211 will not alter performanceComparing Summary
|
|
@danielroe |
|
interesting point. maybe we can revisit the attributes returned in this render function? CodeRabbit also noticed a valid issue with |
|
According to CSS Transforms Level 2,
So our current code using https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/scaleX |
🔗 Linked issue
resolves #33210
📚 Description
Fixes a bug in the Nuxt loading indicator where
backgroundSizecould becomeInfinitywhenprogress.valuewas 0.Before:
After: