← Back to Pull requests

fix: keep each application's Next.js cache apart and fail a deploy with no build, for PR previews #91

Closed
unknown closed this pull request without merging on Nov 25, 2026 17:01 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 21:56 UTC
Author

<img src="https://github.com/user-attachments/assets/3a23025f-8faf-494c-a83f-e945d16b8cb6" alt="A squirrel sorts painted pages into separate baskets for an old oak and a sapling while one bell rings over both" title="A squirrel sorts painted pages into separate baskets for an old oak and a sapling while one bell rings over both" align="right" width="256">

<!-- tour: none @a60c418 — the Changes list links each file -->

⊙ Problem

Running a Next.js app as a Harper pull request preview (HarperFast/harper#3042) showed two defects. With dataMode=shared, preview and production shared ISR rows, so production served the preview's render, even after the drop; any two Next.js apps on one cluster collide this way. And a preview deployed without .next was certified, then answered 404.

💡 Solution

The Harper-backed cache handler stores each application's ISR and Data Cache entries under its name, and caches nothing when it can't tell its application. A prebuilt app with no build now fails its deploy with the reason. The README gets a "Pull request previews" section.

🔧 Changes

  • src/cacheNamespace.cts: the plugin registers each app directory under its Harper name just before prepare(), and a failed start removes only its own registration. Lookups by serverDistDir are memoized, since Next.js builds a handler per request; without one, the worker's only app is used.

  • src/CacheHandler.cts: reads and writes use <app>:<key>; with no app, get and set do nothing. Tags stay unprefixed: they name data, so a shared-data preview's revalidateTag() still expires production's matching entries.

  • src/storageKey.cts, src/UseCacheHandler.cts: the 'use cache' handler's long-key hashing moves to its own module so ISR keys use it too.

  • src/prebuilt.ts, src/plugin.ts: a missing .next, BUILD_ID or an empty one throws, and no failure row is written over the serving release's.

  • README.md, schema.graphql: the previews section (CI build, data mode, server actions, basePath, cache directories, unsupported modes) and the new key format.

  • integrationTests/next-16-caching.pw.ts: the route matcher reads past the app prefix.
  • ✅ Verification

  • Performance: the added work per cache operation measures about 5 ns on Node 24 (memoized lookup, concatenation, length check). Against an in-memory fake table, construct-plus-get is about 0.2 µs slower than main, mostly hashing a fresh key string, which a real Harper get does anyway when it encodes the key.

  • The namespace tests fail on main and pass here, with prebuiltBuildId tests; npm test 257 passing. The integration suites were not run locally (no loopback alias pool here).

  • End to end on a local Harper built from main, with enable_previews and harper preview deploy of a create-harper Next.js app using cacheHandlerPath(): in shared mode production served variant=preview before; after, each app keeps its own rows and production stays variant=production. A preview deployed without .next now fails: release … failed to load in its canary worker: … Prebuilt mode is enabled, but …/.next does not exist.
  • Follow-ups filed: #87, #88, #89, #90, and a comment on #75. Companion: HarperFast/nextjs-example#6 has the preview workflows the README links.

    🤖 Generated with Claude Code

    Related PRs: none found

    <!-- review-deferrals:start -->

    Deferred findings

  • 7ed8cc4534a9ae1e minor correctness — src/plugin.ts — Build-time handlers (Next 14 dedup, read-only children) resolve no namespace and cache nothing — NOT FILED

  • 46a82b8edf6ad17b minor reliability — src/cacheNamespace.cts — No-serverDistDir handler on a multi-app worker silently skips the cache — NOT FILED

  • 264cffa5ec318132 minor data-integrity — src/plugin.ts — Prebuilt success row written before prepare can replace the serving release's row — filed https://github.com/HarperFast/nextjs/issues/89

  • 9c1b2d751fc7f566 minor documentation — README.md — README promises nextjs-example preview workflows not yet on its default branch — NOT FILED

  • <!-- review-deferrals:end -->

    <sub>Review-Coverage: authored=claude; ran=cursor-composer,gemini,codex,cursor-grok; late=cursor-grok:adjudicated; adjudicated=domain; declined=muse; rounds=4; full=3 @ a60c418e1eb0</sub>

    <sub>Review-Attention: study ~20m (critical: schema.graphql, storageKey.cts; decisions: namespace-key-source, fail-closed-unknown-app, shared-tags, cold-cache-upgrade, do-less-alternative, requirement-shift, perf-cost) @ a60c418e1eb0</sub>

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: Ethan-Arrowood Review duration: 1145m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #91"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%