Skip to content

fix(admin): sync form state when editing taxonomy terms - #221

Merged
ascorbic merged 4 commits into
emdash-cms:mainfrom
tohaitrieu:fix/taxonomy-form-state
Apr 8, 2026
Merged

ascorbic merged 4 commits into
emdash-cms:mainfrom
tohaitrieu:fix/taxonomy-form-state

Conversation

@tohaitrieu

@tohaitrieu tohaitrieu commented Apr 4, 2026 •

Copy link
Copy Markdown

What does this PR do?

Fixes TermFormDialog not updating form fields when switching between different taxonomy terms. The dialog was using useState with initial values from the term prop, but React only uses initial values on first mount, causing the form to show stale data when editing different terms.

Added a useEffect hook that syncs form state (label, slug, parentId, description) whenever the term prop changes.

Closes #220

Type of change

  • Bug fix
  • Feature (requires approved Discussion)
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

@changeset-bot

changeset-bot Bot commented Apr 4, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 924157a

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

This PR includes changesets to release 10 packages
Name Type
@emdash-cms/admin Patch
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/plugin-ai-moderation Patch
@emdash-cms/plugin-atproto Patch
@emdash-cms/plugin-audit-log Patch
@emdash-cms/plugin-color Patch
@emdash-cms/plugin-embeds Patch
@emdash-cms/plugin-forms Patch
@emdash-cms/plugin-webhook-notifier 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

@github-actions

github-actions Bot commented Apr 4, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@tohaitrieu

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

The TermFormDialog component wasn't updating form fields when switching
between different terms because React's useState only uses initial values
on first mount.

Add useEffect to sync form state (label, slug, parentId, description)
when the term prop changes.

Fixes emdash-cms#220

@BenjaminPrice BenjaminPrice left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Clean, focused fix — adds a useEffect to sync TermFormDialog form state when the term prop changes, resolving stale fields when switching between taxonomy terms.

Tested scenarios

  • Opened the edit dialog for a taxonomy term and confirmed form fields (label, slug, description, parent) populate correctly.
  • Switched from one term to another and verified all fields update to reflect the newly selected term.
  • Opened a new-term dialog after editing an existing term and confirmed fields reset to empty defaults.
  • Verified auto-slug generation re-enables when switching from an existing term to the new-term form.
  • Confirmed error state clears when switching between terms.
  • Edited a term, saved, then re-opened the dialog to verify persisted values load correctly.

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@pkg-pr-new

pkg-pr-new Bot commented Apr 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@221

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@221

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@221

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@221

emdash

npm i https://pkg.pr.new/emdash@221

create-emdash

npm i https://pkg.pr.new/create-emdash@221

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@221

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@221

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@221

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@221

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@221

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@221

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@221

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@221

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@221

commit: 924157a

@JULJERYT

JULJERYT commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

great!

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@ascorbic
ascorbic merged commit bfcda12 into emdash-cms:main Apr 8, 2026
25 checks passed
This was referenced Apr 8, 2026
fmhall pushed a commit to fmhall/emdash that referenced this pull request Apr 13, 2026
* fix(admin): sync form state when editing taxonomy terms

The TermFormDialog component wasn't updating form fields when switching
between different terms because React's useState only uses initial values
on first mount.

Add useEffect to sync form state (label, slug, parentId, description)
when the term prop changes.

Fixes emdash-cms#220

* chore: add changeset for taxonomy form state fix

---------

Co-authored-by: Matt Kane <[email protected]>
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.

Bug: TermFormDialog doesn't update form state when editing different terms

4 participants