Skip to content

Conversation

@DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Dec 19, 2025

What does this PR do?

Once an applicant has a USRN, prefetch the /roads request in the background. This will result in less overall wait time for an applicant, as the (often long-running) request is running quietly in the background whilst they navigate through PropertyInformation and DrawBoundary.

Context

This is one of the very nice benefits of the switch to TanstackQuery!

As this request can take ~25s (e.g. https://api.editor.planx.dev/roads?usrn=20499403), even if they only spend a few seconds each on the PropertyInformation and DrawBoundary components this is still less time spent waiting at a loading screen.

Why not also do this for the Planning Data query?
We certainly could, but the complexity to reward ratio here is a little off here in my opinion.

Most requests to planning data take ~400ms which is pretty quick - this is our max time saving possible. The point as which we can prefetch can also be much later as we need the siteBoundary for this. For all "happy paths" (where a user accepts a title boundary) we can prefetch at the same spot. The complexity here though is that unhappy paths will invalidate the prefetched query - if the user amend their geom, the request will re-fire anyway once they reach planning constraints.

Having said this though, it could be nice to have Planning Constraints be basically instant...! 🪄

To test...

  • Open a flow which makes a planning constraints request, e.g. https://5942.planx.pizza/buckinghamshire/apply-for-a-lawful-development-certificate/preview
  • Open "Network" tab
  • Reach FindProperty, search address
    • The following address will hit a classified road constraint - 419 Amersham Rd, Hazlemere, High Wycombe HP15 7JG
  • Once the address is selected, the /roads?... query can be seen as started
    • Changing address triggers another request
  • Wait for request to end (optional - this is non-blocking)
  • Navigate forwards to PlanningConstraints
  • /roads?... query is not retriggered, but information is still displayed from prior query ✅
Screen.Recording.2025-12-19.at.13.34.25.mov

@DafyddLlyr DafyddLlyr marked this pull request as draft December 19, 2025 12:13
@github-actions
Copy link

github-actions bot commented Dec 19, 2025

Removed vultr server and associated DNS entries

queryFn: () => getClassifiedRoads(usrn),
enabled: shouldFetchRoads,
refetchOnWindowFocus: false,
staleTime: Infinity,
Copy link
Contributor Author

@DafyddLlyr DafyddLlyr Dec 19, 2025

Choose a reason for hiding this comment

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

staleTime as well as the queryKey must match for there to be a cache hit.

Infinity in this context seems appropriate - it just means "don't refetch for this key (USRN) again this browser session". If a user refreshes, or does a save and return, it will refetch.

@DafyddLlyr DafyddLlyr requested a review from a team December 19, 2025 13:39
@DafyddLlyr DafyddLlyr marked this pull request as ready for review December 19, 2025 13:39
Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

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

Simple and so effective, great work !

@DafyddLlyr DafyddLlyr merged commit 0f0d8c8 into main Jan 7, 2026
15 checks passed
@DafyddLlyr DafyddLlyr deleted the dp/prefetch-planning-constraints branch January 7, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants