Next.js: preserve requirements through advanced agent edits
Work through TypeScript examples of real application boundaries: Authorize a Next.js Server Action at the database write; Prevent private Next.js order responses from entering shared caches. Each recipe includes implementation code, integration prerequisites, failure-path tests to add, a Perch rule, and the captured broken/fixed source checks.
Download the Next.js rule pack ZIP · Inspect the YAML rules
TypeScript
A Server Action is a server entry point. Hiding a button or protecting a layout does not authorize the mutation itself. Put identity scope and current state in the conditional write so the action remains protected when called directly.
Broken edit flagged · corrected edit passes
TypeScript
Authorization can be correct while a shared cache serves the previous customer’s response to the next request. Explicit private, no-store headers express the boundary to browsers and intermediaries; the tenant-scoped query expresses it to the database.
Broken edit flagged · corrected edit passes
Introductory framework example
Use a correction as a saved requirement
Choose the failure you need to prevent, add the scoped rule to your repository, and check both the broken and corrected implementation. Ask your agent to inspect the finding, repair the code and recheck the same rule. Keep framework tests beside the model check.
Perch keeps the requirement beside the code. Reuse the named check during the agent’s next edit and in CI, with cached answers free on unchanged requests.
Official Next.js documentation · All language and framework recipes