Skip to content

fix: sync TermFormDialog state when switching between edit targets - #239

Closed
JiayuuWang wants to merge 1 commit into
emdash-cms:mainfrom
JiayuuWang:contribot/fix-term-form-dialog-state
Closed

JiayuuWang wants to merge 1 commit into
emdash-cms:mainfrom
JiayuuWang:contribot/fix-term-form-dialog-state

Conversation

@JiayuuWang

Copy link
Copy Markdown

Summary

Fixes #220

When clicking Edit on different taxonomy terms, the form dialog retains data from the previously edited term because React.useState only uses its initial value on first mount — subsequent prop changes don't update state automatically.

  • Add a useEffect in TermFormDialog that resets all form fields (label, slug, parentId, description, autoSlug, error) whenever the term prop changes
  • This ensures the form always shows the correct data for the currently selected term

Steps to reproduce the bug

  1. Go to Taxonomies > Categories
  2. Click Edit on "Category A" — form shows Category A's data ✓
  3. Close the dialog without saving
  4. Click Edit on "Category B" — form still shows Category A's data ✗ (bug)

After this fix, step 4 correctly shows Category B's data.

Test plan

  • Click Edit on a term → form shows correct data
  • Close dialog, click Edit on a different term → form updates to show new term's data
  • Slug auto-generation is disabled when editing an existing term (autoSlug = false)
  • Slug auto-generation is enabled for new terms (Add button)
  • Error state is cleared when switching between terms

🤖 Generated with Claude Code

React's useState only uses the initial value on first mount. When the
term prop changes (e.g. user clicks Edit on a different term), the form
fields stayed populated with the previously edited term's data.

Add a useEffect that resets all form fields whenever the term prop
changes, ensuring the dialog always reflects the currently selected term.

Fixes emdash-cms#220
@changeset-bot

changeset-bot Bot commented Apr 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: adfcb00

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions

github-actions Bot commented Apr 4, 2026

Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


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


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@barckcode

Copy link
Copy Markdown
Contributor

Hey! Just a heads up — PR #221 seems to address the same issue and already has maintainer approval from @ascorbic. Might be worth checking if that one covers your approach before investing more time here.

@ascorbic

Copy link
Copy Markdown
Member

Thanks @JiayuuWang . As @barckcode says, this has already been fixed in #221

@ascorbic ascorbic closed this Apr 14, 2026
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

3 participants