Skip to content

Fix controlled input transform handling#9

Merged
dwene merged 1 commit into
mainfrom
codex/fix-controlled-input-transforms
Jun 24, 2026
Merged

Fix controlled input transform handling#9
dwene merged 1 commit into
mainfrom
codex/fix-controlled-input-transforms

Conversation

@dwene

@dwene dwene commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • bump @lambdacurry/medusa-forms to 0.3.0
  • allow ControlledInput and ControlledCurrencyInput rules to include RHF transform helpers
  • apply valueAsNumber/valueAsDate/setValueAs before updating RHF state while preserving default behavior
  • serialize transformed field state back into DOM-safe input values so NaN/Date/null values do not leak into rendered inputs
  • keep currency inputs storing sanitized strings by default, with numeric state available via valueAsNumber or custom setValueAs
  • pass formErrors through ControlledCurrencyInput and add executable Storybook coverage for transforms/error rendering
  • run Storybook browser tests in CI

Validation

  • ./node_modules/.bin/biome check packages/medusa-forms/src/controlled/ControlledInput.tsx packages/medusa-forms/src/controlled/ControlledCurrencyInput.tsx packages/medusa-forms/src/controlled/valueTransforms.ts apps/docs/src/medusa-forms/ControlledInput.stories.tsx apps/docs/src/medusa-forms/ControlledCurrencyInput.stories.tsx
  • ./node_modules/.bin/tsc --noEmit -p packages/medusa-forms/tsconfig.json --types vite/client
  • node .yarn/releases/yarn-4.9.1.cjs workspace @lambdacurry/medusa-forms build
  • node .yarn/releases/yarn-4.9.1.cjs workspace @lambdacurry/medusa-forms-docs build-storybook
  • node .yarn/releases/yarn-4.9.1.cjs workspace @lambdacurry/medusa-forms-docs test (51 passed)

Notes

  • yarn workspace @lambdacurry/medusa-forms type-check currently fails because the shared tsconfig references missing @react-router/node types.
  • yarn workspace @lambdacurry/medusa-forms lint resolved a Biome 2.x binary in the workspace script and rejected the repo's Biome 1.9 config; direct root Biome 1.9.4 on the touched files passes.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@dwene, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 45 minutes and 37 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: adf9da1f-fa09-49d3-a6ae-04522a111c6c

📥 Commits

Reviewing files that changed from the base of the PR and between fa9925b and f171e01.

📒 Files selected for processing (7)
  • .github/workflows/test.yml
  • apps/docs/src/medusa-forms/ControlledCurrencyInput.stories.tsx
  • apps/docs/src/medusa-forms/ControlledInput.stories.tsx
  • packages/medusa-forms/package.json
  • packages/medusa-forms/src/controlled/ControlledCurrencyInput.tsx
  • packages/medusa-forms/src/controlled/ControlledInput.tsx
  • packages/medusa-forms/src/controlled/valueTransforms.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-controlled-input-transforms

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

@github-actions

Copy link
Copy Markdown

📝 Storybook Preview: View Storybook

This preview will be updated automatically when you push new changes to this PR.

Note: The preview will be available after the workflow completes and the PR is approved for deployment.

@dwene dwene marked this pull request as ready for review June 24, 2026 13:30

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6550cf4d77

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

onChange(evt);
}
field.onChange(evt);
field.onChange(hasTransform ? transformValue(getEventValue(evt), rules) : evt);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep transformed values out of the DOM input value

When a transform rule is enabled, this stores the transformed value directly in RHF state, but the next render still spreads field.value back into <Input> as the DOM value. That breaks common transform cases: clearing a valueAsNumber field stores NaN and produces a React input warning, while valueAsDate stores a Date object that a type="date" input cannot display as its required yyyy-mm-dd string. The component needs a separate serialized display value (or equivalent mapping) while keeping the transformed value in form state.

Useful? React with 👍 / 👎.

@currybot-lc currybot-lc Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍛 Currybot Review

📋 Context

  • Ticket: N/A — PR is scoped to fixing ControlledInput support for RHF transform helpers (valueAsNumber, valueAsDate, setValueAs) and surfacing ControlledCurrencyInput errors.
  • Related: RAG searches for this PR/topic returned no matching prior docs or decisions.
  • Cursor rules consulted: medusa-forms-patterns.mdc, medusa-stories-patterns.mdc, react-typescript-patterns.mdc, ui-component-patterns.mdc, storybook-testing.mdc.
  • DevAgent plan: N/A.
  • Scope: ✅ matches the PR description.

🔍 Gap Analysis

  • The implementation addresses the core gap: transform-only RHF rule options are now accepted by ControlledInput, applied before updating RHF state, and intentionally stripped before passing validation rules to Controller.
  • ControlledCurrencyInput now passes formErrors through to the UI component, which aligns with the Medusa Forms FieldWrapper error-display pattern.
  • No ticket or plan context was available beyond the PR body, so there were no external acceptance criteria to validate against.

🧪 Code Quality

  • valueAsNumber, valueAsDate, and setValueAs handling is small and localized.
  • ✅ Existing event-based behavior is preserved when no transform rule is present.
  • ✅ The controlled component still calls consumer onChange before updating RHF state, matching the established controlled component pattern.
  • ⚠️ The new Storybook examples demonstrate the transform behavior visually, but they do not add interaction/play assertions. Since this is regression-prone form behavior, adding Storybook play checks for ValueAsNumber and SetValueAs would make the coverage stronger.

🔧 Simplicity Audit

  • No violations found.
  • Simplicity deductions applied: 0. The helper extraction is proportionate to the problem and avoids pushing transform-specific logic into the render callback.

🌟 Highlights

  • Nice preservation of the default field.onChange(evt) path; that keeps behavior stable for regular text inputs.
  • The rule destructuring makes the intent clear: RHF validation rules still go through Controller, while transform helpers are handled locally.
  • Good docs coverage via focused stories that show the resulting value/type, which makes the fix easy to inspect manually.

📊 Merge Confidence: 9.2/10

  • ✅ Builds and typechecks passed locally:
    • ./node_modules/.bin/tsc --noEmit -p packages/medusa-forms/tsconfig.json --types vite/client
    • ./node_modules/.bin/biome check ...touched files...
    • node .yarn/releases/yarn-4.9.1.cjs workspace @lambdacurry/medusa-forms build
    • node .yarn/releases/yarn-4.9.1.cjs workspace @lambdacurry/medusa-forms-docs build-storybook
  • ⚠️ Would raise to 9.5+ with executable Storybook play assertions for the two transform stories.
  • 🔧 Simplicity deductions applied: 0 total.

@dwene dwene force-pushed the codex/fix-controlled-input-transforms branch from 6550cf4 to 77c5416 Compare June 24, 2026 13:36
@dwene dwene force-pushed the codex/fix-controlled-input-transforms branch from 77c5416 to c16560f Compare June 24, 2026 13:47
@dwene dwene force-pushed the codex/fix-controlled-input-transforms branch from c16560f to 8b3a21a Compare June 24, 2026 13:53
@dwene dwene force-pushed the codex/fix-controlled-input-transforms branch from 8b3a21a to b7e35e2 Compare June 24, 2026 14:00
@dwene dwene force-pushed the codex/fix-controlled-input-transforms branch from b7e35e2 to f171e01 Compare June 24, 2026 14:04
@dwene dwene merged commit 742ec34 into main Jun 24, 2026
5 checks passed
@dwene dwene deleted the codex/fix-controlled-input-transforms branch June 24, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant