Skip to content

Preserve empty string array values in submissions#1233

Merged
edmundhung merged 1 commit into
edmundhung:mainfrom
morgan-coded:fix/839-array-empty-string
Jun 14, 2026
Merged

Preserve empty string array values in submissions#1233
edmundhung merged 1 commit into
edmundhung:mainfrom
morgan-coded:fix/839-array-empty-string

Conversation

@morgan-coded

@morgan-coded morgan-coded commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

parseWithZod could drop an empty string inside an array field because that value was treated like it was absent. That can lose or shift array entries in the parsed submission payload.

This narrows the presence check so only undefined is treated as missing. I checked it with the focused conform-dom submission test, changed-file oxlint, changed-file oxfmt --check, and git diff --check.

Closes #839

Generated Summary

Changes

Modified the presence check in packages/conform-dom/submission.ts to preserve empty string values in array fields. The reducer now treats only undefined as missing (previously treated any falsy value as missing):

// Before: !prev (treats empty string as missing)
// After: prev === undefined (only undefined is missing)

This ensures empty string elements in arrays are not dropped during form submission parsing, maintaining correct array indices and element ordering.

Additional updates

  • Added Changesets entry documenting the behavior change
  • Added test verifying empty strings are preserved within array fields during parsing

Copilot AI review requested due to automatic review settings June 9, 2026 15:03
@changeset-bot

changeset-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b51f716

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@conform-to/dom Patch
@conform-to/react Patch
@conform-to/valibot Patch
@conform-to/yup Patch
@conform-to/zod Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 54eda280-b290-42d6-9276-6d54a560f7cd

📥 Commits

Reviewing files that changed from the base of the PR and between c7f8874 and b51f716.

📒 Files selected for processing (3)
  • .changeset/fix-array-empty-string.md
  • packages/conform-dom/submission.ts
  • packages/conform-dom/tests/submission.test.ts
📜 Recent review details
🧰 Additional context used
🪛 markdownlint-cli2 (0.22.1)
.changeset/fix-array-empty-string.md

[warning] 5-5: First line in a file should be a top-level heading

(MD041, first-line-heading, first-line-h1)

🔇 Additional comments (3)
.changeset/fix-array-empty-string.md (1)

1-5: LGTM!

packages/conform-dom/submission.ts (1)

104-110: LGTM!

packages/conform-dom/tests/submission.test.ts (1)

285-309: LGTM!


📝 Walkthrough

Walkthrough

This PR fixes a bug in the form submission payload builder where empty strings and other falsy-but-valid values (0, false) were being lost in array fields. The fix changes the value-merging logic to only treat undefined as "no prior value," and includes a test case verifying empty strings are preserved.

Changes

Empty string preservation in array fields

Layer / File(s) Summary
Fix falsy value handling in submission context
.changeset/fix-array-empty-string.md, packages/conform-dom/submission.ts
The getSubmissionContext reducer now checks prev === undefined instead of !prev when determining whether to overwrite or accumulate array field values, so empty strings and other falsy values are no longer dropped. Changeset documents this as a patch release for @conform-to/dom.
Test empty string preservation in arrays
packages/conform-dom/tests/submission.test.ts
New test case submits array entries with empty strings interspersed and verifies the parsed payload retains all entries in order.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A string so empty, once was lost,
Within the arrays, falsy crossed,
But now undefined marks the way,
And empty values get to stay! ✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: preserving empty string values in array submissions, which is the core focus of the PR.
Linked Issues check ✅ Passed The changes fully address issue #839 by narrowing the presence check from falsy values to only undefined, ensuring empty strings are preserved in array fields during submission parsing.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the empty string array preservation issue; the changeset entry, submission logic fix, and test are all in scope and focused on issue #839.

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

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


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.

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR fixes how submission payloads are constructed for repeated (array) fields so that empty string values are preserved instead of being treated as “missing”.

Changes:

  • Adjust payload aggregation logic to treat only undefined as “no previous value” (preserving falsy values like '').
  • Add a regression test covering empty strings within array fields.
  • Add a changeset describing the patch fix for @conform-to/dom.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/conform-dom/tests/submission.test.ts Adds a test ensuring parse() preserves empty strings in repeated fields.
packages/conform-dom/submission.ts Fixes array-field accumulation by not treating '' as an absent previous value.
.changeset/fix-array-empty-string.md Documents the patch release and behavior change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/conform-dom/submission.ts
@pkg-pr-new

pkg-pr-new Bot commented Jun 9, 2026

Copy link
Copy Markdown
More templates

@conform-to/dom

npm i https://pkg.pr.new/@conform-to/dom@1233

@conform-to/react

npm i https://pkg.pr.new/@conform-to/react@1233

@conform-to/valibot

npm i https://pkg.pr.new/@conform-to/valibot@1233

@conform-to/validitystate

npm i https://pkg.pr.new/@conform-to/validitystate@1233

@conform-to/yup

npm i https://pkg.pr.new/@conform-to/yup@1233

@conform-to/zod

npm i https://pkg.pr.new/@conform-to/zod@1233

commit: b51f716

@edmundhung edmundhung left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks!

@edmundhung edmundhung merged commit af2582e into edmundhung:main Jun 14, 2026
19 checks passed
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.

parseWithZod fails to parse Arrays containing empty strings ('') correctly

3 participants