Fix duplicate HTTP requests on initial DAG page load #59766
Closed
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.
Prevent unnecessary cache invalidation when the DAG run ID is first loaded. Previously, when a page was initially loaded, the cache would be cleared and queries re-fetched even though the data hadn't changed, resulting in duplicate HTTP requests visible in the network tab.
The fix checks if this is the first time the DAG run ID is being set (previousDagRunIdRef.current === undefined) and if so, sets the ref without invalidating the query cache. Cache invalidation now only occurs when there is an actual new DAG run, which is the intended behavior.
Fixes duplicate requests for /ui/grid/runs, /ui/grid/structure, and other API endpoints on pages like http://localhost:8000/dags/example_branch_labels
Fix duplicate HTTP requests on initial DAG page load
This PR resolves an issue where the UI was making duplicate HTTP requests on initial page load, causing unnecessary network traffic and potential performance degradation.
Problem:
When loading a DAG page (e.g.,
http://localhost:8000/dags/example_branch_labels), theuseRefreshOnNewDagRunshook was incorrectly invalidating the query cache on the first render. This occurred because:previousDagRunIdRef.currentis initialized asundefinedlatestDagRunIdis fetched for the first time, it differs fromundefinedpreviousDagRunIdRef.current !== latestDagRunIdtriggers cache invalidation/ui/grid/runs,/ui/grid/structure, etc.Solution:
Added an early return when
previousDagRunIdRef.currentisundefined(initial load). The ref is set without invalidating queries, ensuring cache invalidation only occurs when a genuinely new DAG run appears:Impact:
Testing: