Skip to content

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

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

fix: sync TermFormDialog state when switching between edit targets#239
JiayuuWang wants to merge 1 commit intoemdash-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
Copy link
Copy Markdown

changeset-bot bot commented Apr 4, 2026

⚠️ 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
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026


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.

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

1 participant