Re-implement Server Action reducer (#86367)#9
Open
MitchLewis930 wants to merge 1 commit intopr_039_beforefrom
Open
Re-implement Server Action reducer (#86367)#9MitchLewis930 wants to merge 1 commit intopr_039_beforefrom
MitchLewis930 wants to merge 1 commit intopr_039_beforefrom
Conversation
Rewrite of the Server Action reducer to use the PPR/Segment Cache navigation implementation, rather than the old lazy fetch implementation. Server Actions may trigger a revalidation, a redirect, or both. They may also invalidate the cache. The behavior could be naively implemented using router.refresh() and router.push(). Semantically, the routing behavior is equivalent. The main difference is that the server that invokes the action may also send back new data for the page within the same response. Compared to a separate request, this data is more likely to be consistent with any data that may have been mutated by the action, due to global data propagation races. (It's also faster since it avoids an extra server waterfall.) So, navigations initiated by a Server action must be able to "seed" the navigation with the data it just received from the server. I've added a new internal method, navigateToSeededRoute, that implements this behavior.
Greptile OverviewGreptile SummaryThis PR re-implements the server action reducer to use a unified navigation approach. The main changes include:
The implementation prioritizes using data from server action responses over separate requests for better performance and consistency with mutations just performed by the action. Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant ServerActionReducer
participant FetchServerAction
participant Server
participant NavigationSystem
participant PPRNavigations
participant CacheNode
Client->>ServerActionReducer: Execute server action
ServerActionReducer->>FetchServerAction: fetchServerAction(state, nextUrl, action)
FetchServerAction->>Server: POST request with action
Server-->>FetchServerAction: ActionFlightResponse {a, f, q, i, b}
Note over Server,FetchServerAction: q: renderedSearch<br/>i: couldBeIntercepted
FetchServerAction-->>ServerActionReducer: Return response data
alt Has redirect
ServerActionReducer->>Client: Reject promise with redirectError
else No redirect
ServerActionReducer->>Client: Resolve promise with actionResult
end
alt Has flight data
ServerActionReducer->>NavigationSystem: navigateToSeededRoute(url, seedData, seedHead)
NavigationSystem->>PPRNavigations: startPPRNavigation with seedData
Note over PPRNavigations: Prefer seedData over prefetchData<br/>for consistency with server action writes
PPRNavigations->>CacheNode: Create/update cache nodes
PPRNavigations-->>NavigationSystem: Return navigation task
NavigationSystem-->>ServerActionReducer: Return navigation result
else No flight data but revalidated
ServerActionReducer->>NavigationSystem: navigateUsingSegmentCache(shouldRefreshDynamicData=true)
NavigationSystem->>PPRNavigations: Refresh dynamic data
PPRNavigations-->>NavigationSystem: Return navigation task
NavigationSystem-->>ServerActionReducer: Return navigation result
else No changes
ServerActionReducer-->>Client: Return unchanged state
end
ServerActionReducer-->>Client: Return updated router state
|
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.
PR_039