Repository navigation
Add flow contracts to apply invalidations on the server - #2
Merged
Merged
Conversation
A live Next.js 15.5 check showed that forwarding the AbortSignal did not throw, so describe the change as removing a misleading argument rather than fixing a serialization failure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Declare invalidate/consistency once with defineFlowContract in a module shared by server and client. withFlowContract (mutaflow/next/server) applies the contract after the server action succeeds; the client flow spreads the same contract so events and devtools report exactly what the server invalidated. runFlow and the server wrapper share resolveFlowContract, so the lists cannot drift. - Type tags/paths builders recursively so nested segments are builders. - Move examples/next-app to a shared contract; drop updateTag, which Next.js 15 does not export, so the example typechecks and builds. - Update READMEs, concepts guide and changelog; add tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
javaquasar
changed the base branch from
claude/repository-analysis-improvements-7e17f9
to
main
December 2, 2026 10:59
4 of 5 tasks
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.
Summary
Until now,
invalidateandconsistencyincreateFlowwere metadata only. They appeared in events and devtools but never touched the Next cache. The real invalidation had to be written a second time inside the Server Action, and the two lists could drift apart. The Next.js example had exactly this drift: the server invalidated/todos/<id>while the client reported/todos/byId/<id>.This PR adds flow contracts, so the cache effects of a mutation are declared once:
Changes
mutaflow:defineFlowContract,resolveFlowContract, and theFlowContractandResolvedFlowContracttypes.runFlownow uses the shared resolver.mutaflow/next/server:withFlowContract(contract, action, bindings, { pathType, onApplied })andcreateNextServerHelpers(...).withContract(...). The contract is applied only after the action succeeds, and the action receives onlyinput.tags/pathsbuilders are typed recursively. Nested segments used to beunknown, sotags.todos.byId(id)did not typecheck.examples/next-appuses a shared contract. It typechecks and builds again: it used to importupdateTag, which Next.js 15 does not export.AbortSignalfrom the old server action adapter did not throw, so the entry no longer calls it a serialization failure.Test plan
npm test: 44/44 (5 new tests, including one that checks the server and the client report the same invalidations)npm run typecheckexamples/next-app:tsc --noEmitandnext buildon Next.js 15.5onApplied) and the devtools panel show identical invalidations:todos.list,todos.byId.<id>,/todos/<id>🤖 Generated with Claude Code