fix: prevent infinite API loop on invalid environment URLs#7284
Draft
talissoncosta wants to merge 1 commit intomainfrom
Draft
fix: prevent infinite API loop on invalid environment URLs#7284talissoncosta wants to merge 1 commit intomainfrom
talissoncosta wants to merge 1 commit intomainfrom
Conversation
Closes #7283 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I have added information todocs/if required so people know about the feature.Changes
Closes #7283
When the URL contained an environment key that didn't belong to the current project (deleted env, typo, env from another project, stale bookmark, or permission revoked mid-session), the app entered an infinite API request loop and showed a sidebar loader that never resolved. Further requests appeared with the literal string
undefinedin the path.Root cause
Two bugs compounded:
EnvironmentReadyCheckerpolled every 1s with no error off-ramp. It only stopped polling on a successful response withis_creating: false— on a 4xx it kept polling forever.api_keyregardless of project scope, so a valid env key belonging to a different project returns200 OKand the checker falls through to render the page. Downstream components then fire queries with missing or stale env context — some usingenv?.api_keyin URL templates without a fallback, producing/api/v1/environments/undefined/...URLs.Sibling sidebar components (
EnvironmentAside,EnvironmentNavbar) conflated "env list loading" with "env missing from list" and showed loaders forever.Fix
EnvironmentReadyChecker: source of truth is now the project's env list (useGetEnvironmentsQuery). If the URL env isn't in the list, render an "Environment not found" state. The single-env poll is kept for theis_creatinghappy path but now skips once polling is complete or the env is known missing.useEffect) when the env ID changes, so recovering via URL change is instant and doesn't flash stale children.LoadingState,CreatingState,NotFoundStatecomponents; render flow is now guard clauses instead of nested ternaries./environment/createsentinel so the new-env form isn't caught.EnvironmentAside: hides the whole sidebar when the env isn't in the project list.EnvironmentNavbar:skip: !environmenton the change-request queries (no moreundefinedURL fetches); returnsnullwhen env isn't in the list.`${projectId}`template coerces in the two files touched (fixes pre-existingstring not assignable to numberTS errors).How did you test this code?
Manual verification on local dev server (
ENV=local npm run dev):/project/<id>/environment/<invalid-key>/features→ shows "Environment not found" in the main area, sidebar hidden, no repeat requests in Network tab./project/<id>/environment/<valid-key>/features→ loads features normally./project/<id>/environment/create→ create form renders (sentinel preserved)./environments/undefined/...URLs fire in any of the above flows.