Description
When editing taxonomy terms in the admin UI, the form fields don't update when switching between different terms. The form continues to show data from the previously edited term.
Steps to Reproduce
- Go to Taxonomies > Categories
- Click Edit on "Category A"
- Close the dialog without saving
- Click Edit on "Category B"
- Expected: Form shows Category B's data (label, slug, description)
- Actual: Form still shows Category A's data
Root Cause
In packages/admin/src/components/TaxonomyManager.tsx, the TermFormDialog component uses useState with initial values from the term prop:
const [label, setLabel] = React.useState(term?.label || "");
const [slug, setSlug] = React.useState(term?.slug || "");
const [description, setDescription] = React.useState(term?.description || "");
React's useState only uses the initial value on first mount. When the term prop changes, the state is not updated.
Proposed Fix
Add a useEffect to sync form state when the term prop changes:
// Sync form state when term prop changes (for edit mode)
React.useEffect(() => {
setLabel(term?.label || "");
setSlug(term?.slug || "");
setParentId(term?.parentId || "");
setDescription(term?.description || "");
setAutoSlug(!term);
setError(null);
}, [term]);
I have a fix ready and can submit a PR if this approach is acceptable.
Environment
- EmDash version: latest (main branch)
- Browser: Chrome/Safari
- OS: macOS
Description
When editing taxonomy terms in the admin UI, the form fields don't update when switching between different terms. The form continues to show data from the previously edited term.
Steps to Reproduce
Root Cause
In
packages/admin/src/components/TaxonomyManager.tsx, theTermFormDialogcomponent usesuseStatewith initial values from thetermprop:React's
useStateonly uses the initial value on first mount. When thetermprop changes, the state is not updated.Proposed Fix
Add a
useEffectto sync form state when thetermprop changes:I have a fix ready and can submit a PR if this approach is acceptable.
Environment