Skip to content

fix(settings): Defer sentry app form mount until data loads#115162

Merged
priscilawebdev merged 3 commits into
masterfrom
priscila/fix/sentry-app-form-default-values
May 12, 2026
Merged

fix(settings): Defer sentry app form mount until data loads#115162
priscilawebdev merged 3 commits into
masterfrom
priscila/fix/sentry-app-form-default-values

Conversation

@priscilawebdev
Copy link
Copy Markdown
Member

@priscilawebdev priscilawebdev commented May 8, 2026

The Sentry App edit page mounted useScrapsForm before the app data had finished loading, so the form's internal state was initialized from empty/default values. When the data arrived the form re-rendered, but TanStack Form does not pick up new defaultValues after init — so the rendered values lagged behind the real
data, briefly flashing (e.g. the Alert Rule Action switch flicking from off to on when opening an integration URL directly) and risking a save that overwrote
real values with empty ones.
TanStack Form's defaultValues are reactive — when the real data arrived the form picked up the new defaults and re-rendered, which
is exactly what produced the visible flicker (e.g. the Alert Rule Action switch flipping from off to on when opening an integration URL directly) and risked a
save that overwrote real values with empty ones if the user interacted before the update landed.

Extract the form into a SentryApplicationForm child that the parent only mounts once the app query resolves (or for the new-app route), so useScrapsForm is initialized with the real values on its first render. Tokens are still prefetched in parallel from the parent so the credentials/tokens panel is ready by the time the form mounts.

Before

Screen.Recording.2026-05-08.at.11.30.34.mov

After

Screen.Recording.2026-05-08.at.11.31.09.mov

@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 8, 2026

DE-970

@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

📊 Type Coverage Diff

✅ No new type safety issues introduced. Coverage: 93.47%

@priscilawebdev priscilawebdev force-pushed the priscila/fix/sentry-app-form-default-values branch from 2c02e1b to 34fb535 Compare May 8, 2026 08:41
@priscilawebdev priscilawebdev force-pushed the priscila/fix/sentry-app-form-default-values branch from 34fb535 to a5a77ae Compare May 8, 2026 08:48
@priscilawebdev priscilawebdev force-pushed the priscila/fix/sentry-app-form-default-values branch from a5a77ae to 1628e9d Compare May 8, 2026 08:53
@priscilawebdev priscilawebdev force-pushed the priscila/fix/sentry-app-form-default-values branch from 1628e9d to f972007 Compare May 8, 2026 08:58
@priscilawebdev priscilawebdev force-pushed the priscila/fix/sentry-app-form-default-values branch from f972007 to f9918f7 Compare May 8, 2026 09:13
@priscilawebdev priscilawebdev force-pushed the priscila/fix/sentry-app-form-default-values branch 2 times, most recently from 1f7ef6a to e78739d Compare May 8, 2026 09:18
The Sentry App edit page mounted `useScrapsForm` before the app data
had finished loading, so the form's internal state was initialized
from empty/default values. When the data arrived the form re-rendered
but TanStack Form does not pick up new `defaultValues` after init,
causing visible flashes (e.g. the Alert Rule Action switch flicking
from off to on) and a risk of saving stale values.

Extract the form into `SentryApplicationFormBody`, which the parent
only mounts once the app query resolves (or for the new-app route),
so `useScrapsForm` is initialized with the real values on first
render. Tokens are still prefetched in parallel from the parent so
the credentials panel renders without waiting on a second roundtrip.

Refs #114138
@priscilawebdev priscilawebdev force-pushed the priscila/fix/sentry-app-form-default-values branch from e78739d to 39a785e Compare May 8, 2026 09:19
@priscilawebdev
Copy link
Copy Markdown
Member Author

bugbot run

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 39a785e. Configure here.

@priscilawebdev priscilawebdev marked this pull request as ready for review May 8, 2026 09:34
@priscilawebdev priscilawebdev requested a review from a team as a code owner May 8, 2026 09:34
The detail useQuery uses placeholderData to instantly seed the page
from the list cache (so the breadcrumb name does not flicker). With
placeholderData set, the query reports isLoading=false on first
render, so the form mounted with stale list values. TanStack Form
snapshots defaultValues on mount, so the form ignored the real
response when it arrived and could save stale data.

Also gate the form on isPlaceholderData so it only mounts once the
real fetch resolves. The breadcrumb still uses app?.name from the
placeholder, preserving the no-flicker UX.

Refs #114138
@TkDodo
Copy link
Copy Markdown
Collaborator

TkDodo commented May 11, 2026

When the data arrived the form re-rendered, but TanStack Form does not pick up new defaultValues after init — so the rendered values lagged behind the real data, briefly flashing (e.g. the Alert Rule Action switch flicking from off to on when opening an integration URL directly) and risking a save that overwrote real values with empty ones.

This assessment is wrong. The flickering happens precisely because TanStack Form does pick up defaultValues after init - they have reactive defaultValues.

So yes, the fix is to not render the form if you don’t want to init the form with fallback values that later update themselves, but the statement is not correct (I guess it’s AI?)

@priscilawebdev
Copy link
Copy Markdown
Member Author

priscilawebdev commented May 12, 2026

When the data arrived the form re-rendered, but TanStack Form does not pick up new defaultValues after init — so the rendered values lagged behind the real data, briefly flashing (e.g. the Alert Rule Action switch flicking from off to on when opening an integration URL directly) and risking a save that overwrote real values with empty ones.

This assessment is wrong. The flickering happens precisely because TanStack Form does pick up defaultValues after init - they have reactive defaultValues.

So yes, the fix is to not render the form if you don’t want to init the form with fallback values that later update themselves, but the statement is not correct (I guess it’s AI?)

yes it was auto-generated. Thanks for reading and correcting 🙏 I updated the description

…-app-form-default-values

# Conflicts:
#	static/app/views/settings/organizationDeveloperSettings/sentryApplicationDetails.tsx
@priscilawebdev priscilawebdev enabled auto-merge (squash) May 12, 2026 06:21
@priscilawebdev priscilawebdev merged commit 492c382 into master May 12, 2026
75 checks passed
@priscilawebdev priscilawebdev deleted the priscila/fix/sentry-app-form-default-values branch May 12, 2026 06:24
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