Skip to content

fix(hosting,inertia): Inertia body validation redirects back with field errors; faster first loads - #818

Merged
antosubash merged 8 commits into
mainfrom
fix/inertia-lab-findings
Nov 4, 2026
Merged

antosubash merged 8 commits into
mainfrom
fix/inertia-lab-findings

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Summary

Two findings from testing every Inertia v3 feature end to end in a fresh smpy new app (inertia_lab: 11 feature pages, 78 protocol tests, 50 Playwright browser tests against @inertiajs/react 3.11, plus a load harness).

Behaviour change: Inertia body validation redirects back with field errors

An Inertia useForm POST/PUT/PATCH/DELETE whose body fails FastAPI request validation used to get hosting's 422 Error page ("The requested URL contains invalid parameters."), which replaced the form and lost its URL. It now redirects back (303) with one message per field via redirect_back_with_errors, scoped by X-Inertia-Error-Bag, so the errors show in place, as with Laravel's adapter.

  • Only body errors redirect. A bad path, query or header value keeps the 422 page, because no form field can show it. Query errors that come alongside body errors are not flashed.
  • GETs, non-Inertia requests and API clients are unchanged (error page or JSON).

Perf: catalog-carrying pages

Every first page load carries the shared i18n catalog (48 KB in English). The resolver ran _is_dynamic, including inspect.isawaitable, on every catalog string before its scalar check, and encode_page rebuilt the whole page with jsonable_encoder.

  • The resolver now tests scalars first.
  • Pages built only from exact JSON types skip the encoder. The encoder still handles enums, tuples, non-str keys, _sa* keys and over-deep or cyclic data.
  • Resolve + encode for such a page: 2.27 ms → 0.32 ms.

Lab perf baseline (1 uvicorn worker, SQLite, for context; not changed here)

  • An Inertia navigation takes about 5.3 ms p50, of which Inertia itself is about 0.8 ms.
  • A session-authenticated request costs about 4.5 ms even on /health/live (user and session loading, about 4 SQLite queries).
  • A first load takes about 8.2 ms before this PR.

Tests

  • New framework/hosting/tests/test_hosting_inertia_body_validation.py covers:

    • POST/PUT/PATCH redirect with field errors;
    • the error bag;
    • a bad path param keeps the page;
    • only body errors reach the form;
    • GET, plain browser and API requests are unchanged.

    Verified failing without the fix.

  • Fast-path tests in test_adapter_page.py: plain page returned as-is; enum/tuple, non-str keys and _sa keys use the encoder; cycles terminate.

  • make lint ✓ · make test-py ✓ (7594 passed, 43 skipped). No TS changes.

  • /ship: three review passes (correctness + maintainability). Findings were fixed or rejected with evidence. Optimize was folded into the review. Browser QA was skipped because no framework page submits a FastAPI-validated body; the lab's Playwright suite covered it (strict xfail before this fix).

https://claude.ai/code/session_01FXHA3ZJ5EgoJN4zXTAhBR2

…ld errors; faster catalog-carrying pages

An Inertia form whose JSON body fails FastAPI validation rendered the 422
'invalid parameters' Error page over the form; it now redirects back with
one error per field (error-bag aware), like redirect_back_with_errors.
GETs and non-Inertia requests keep the error page / JSON.

Perf: the resolver checks scalars before _is_dynamic, and encode_page
skips jsonable_encoder for plain-JSON pages. A page carrying the 48KB i18n
catalog drops from 2.27 ms to 0.32 ms in resolve+encode.

Found with the inertia_lab feature lab.

Claude-Session: https://claude.ai/code/session_01FXHA3ZJ5EgoJN4zXTAhBR2
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: ccab8cc
Status: ✅  Deploy successful!
Preview URL: https://f9ab8c52.simple-module-python.pages.dev
Branch Preview URL: https://fix-inertia-lab-findings.simple-module-python.pages.dev

View logs

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-04T14:32:42.994105Z 86dfd20 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@antosubash
antosubash merged commit cedb555 into main Nov 4, 2026
16 checks passed
@antosubash
antosubash deleted the fix/inertia-lab-findings branch November 4, 2026 16:09
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.

1 participant