Skip to content

fix(integrations): preserve async select value in external issue modal after dynamic refetch#115593

Merged
natemoo-re merged 3 commits into
masterfrom
nm/fix/externalIssueForm
May 14, 2026
Merged

fix(integrations): preserve async select value in external issue modal after dynamic refetch#115593
natemoo-re merged 3 commits into
masterfrom
nm/fix/externalIssueForm

Conversation

@natemoo-re
Copy link
Copy Markdown
Member

Previously, selecting a Jira project via async search (one not in the initial dropdown) would lose the selection after the form refreshed — the value was preserved but the label couldn't display because the option wasn't in the static choices list. This regressed in #112094, which migrated the external issue form but dropped the async options caching the old implementation relied on.

In this PR, externalIssueForm.tsx has been updated so async search results are cached and merged into field choices across form remounts, matching the pattern #115456 already applied to ticketRuleModal.tsx. Also added a test covering the full async search + dynamic refetch + form remount cycle to prevent future regressions.

@natemoo-re natemoo-re requested a review from a team May 14, 2026 19:02
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

📊 Type Coverage Diff

Metric Before After Delta
Coverage 93.52% 93.52% ±0%
Typed 135,599 135,613 🟢 +14
Untyped 9,396 9,396 ±0
🔍 1 new type safety issue introduced

Type assertions (as) (1 new)

File Line Detail
static/app/components/externalIssues/externalIssueForm.tsx 332 as JsonFormAdapterFieldConfig[](config ?? []).map(field => { const cachedChoices = asyncOptionsCache[field.nam…

This is informational only and does not block the PR.

Comment thread static/app/components/externalIssues/externalIssueForm.tsx
@natemoo-re natemoo-re enabled auto-merge (squash) May 14, 2026 20:51
@natemoo-re natemoo-re merged commit 953858c into master May 14, 2026
73 checks passed
@natemoo-re natemoo-re deleted the nm/fix/externalIssueForm branch May 14, 2026 20:57
Comment on lines +157 to +165
const handleAsyncOptionsFetched = useCallback(
(fieldName: string, options: Array<SelectValue<string>>) => {
setAsyncOptionsCache(prev => ({
...prev,
[fieldName]: options.map((o): Choice => {
const label = typeof o.label === 'string' ? o.label : String(o.value);
return [o.value, label];
}),
}));
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.

Bug: The handleAsyncOptionsFetched callback overwrites the async option cache on each search, which can cause selected option labels to disappear after a subsequent form remount.
Severity: MEDIUM

Suggested Fix

Modify handleAsyncOptionsFetched to merge new options with the existing options in asyncOptionsCache[fieldName] instead of completely replacing them. This ensures that previously selected values are retained in the cache across searches and subsequent form remounts, even if they don't appear in newer search results.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: static/app/components/externalIssues/externalIssueForm.tsx#L157-L165

Potential issue: The `handleAsyncOptionsFetched` callback completely replaces the
`asyncOptionsCache` for a given field with each new set of search results. If a user
selects an option from an async search (e.g., a specific Jira project), then performs a
second search in the same field whose results do not include the selected option, the
cache entry for the selected option is lost. If the form later remounts due to another
field changing, the UI will no longer have the label for the selected option, showing a
raw ID instead. This is a regression of the bug this PR intended to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants