Skip to content

Commit

Permalink
fix: root key should be updated after form update (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundhung committed Apr 28, 2024
1 parent c005590 commit 8a81644
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/conform-dom/form.ts
Expand Up @@ -435,7 +435,10 @@ function updateValue<Error>(
if (name === '') {
meta.initialValue = value as Record<string, unknown>;
meta.value = value as Record<string, unknown>;
meta.key = getDefaultKey(value as Record<string, unknown>);
meta.key = {
...getDefaultKey(value as Record<string, unknown>),
'': generateId(),
};
return;
}

Expand Down
1 change: 0 additions & 1 deletion playground/app/routes/form-control.tsx
Expand Up @@ -85,7 +85,6 @@ export default function FormControl() {
<button
className="rounded-md border p-2 hover:border-black"
{...form.update.getButtonProps({
name: form.name,
value: {
number: 13579,
name: 'Conform',
Expand Down
11 changes: 11 additions & 0 deletions tests/integrations/form-control.spec.ts
Expand Up @@ -63,6 +63,17 @@ async function runValidationScenario(page: Page) {
await expect(fieldset.message).toHaveValue(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
);

// To ensure that keys are updated correctly
await fieldset.name.fill('Test');
await fieldset.number.fill('2468');
await fieldset.message.fill('Hello World');
await fieldset.updateForm.click();
await expect(fieldset.name).toHaveValue('Conform');
await expect(fieldset.number).toHaveValue('13579');
await expect(fieldset.message).toHaveValue(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
);
}

test.describe('With JS', () => {
Expand Down

0 comments on commit 8a81644

Please sign in to comment.