Skip to content

fix(inertia,hosting): version-header 409s, protocol middleware, single page-object embed (#774, #775, #778) - #800

Merged
antosubash merged 7 commits into
mainfrom
fix/inertia-protocol-middleware-774-778
Nov 3, 2026
Merged

antosubash merged 7 commits into
mainfrom
fix/inertia-protocol-middleware-774-778

Conversation

@antosubash

Copy link
Copy Markdown
Owner

The remaining Inertia v3 protocol gaps from the conformance review (tracking #780): asset-version 409s, the protocol middleware the adapter guide requires, and a single page-object embed.

Closes #774
Closes #775
Closes #778

What changed

  • inertia: missing X-Inertia-Version is not treated as a mismatch; version 409 lacks X-Inertia-Version #774 Asset version: an Inertia GET with a missing X-Inertia-Version is treated as "", so it mismatches a real version, and the 409 now carries X-Inertia-Version as well as X-Inertia-Location. Behaviour change: non-browser callers that send X-Inertia must send the version. The simple_module_test clients (client, authenticated_client, session_client, wizard_client, the integration inertia_client) send the app's current version by default (simple_module_test.inertia_headers(app)). Hand-built test clients in four module test files were updated.
  • inertia: no protocol middleware: 302/307 after PUT/PATCH/DELETE not made 303, fragment redirects and empty 200s not handled #775 InertiaMiddleware: a new pure-ASGI middleware in simple_module_inertia. For X-Inertia requests it:
    • turns a 302/307 after PUT/PATCH/DELETE/QUERY into a 303 (307 included because it is FastAPI's RedirectResponse default);
    • turns a redirect to a URL with a #fragment into a 409 with X-Inertia-Redirect (not for Purpose: prefetch), dropping the discarded body's headers;
    • turns an empty 200 (an explicit Content-Length: 0) into a 303 back to the same-site Referer;
    • adds Vary: X-Inertia to Inertia and HTML responses.
    • It never buffers a streaming body.
    • Hosting installs it between Session and the module middleware, so a redirect issued by module middleware is normalised too. Example: the auth middleware's login redirect for an expired session after a DELETE. With Codex's original placement inside the module stack, that case stayed a 302, and a regression test now pins it.
    • Hosting's cache middleware now uses the inertia package's add_vary.
  • inertia: first-load HTML embeds the page object twice (dead v2 data-page attribute, ~94 KB) #778 Single embed: the HTML embeds the page object once, in <script data-page="app">. The v2 <div data-page='…'> copy is gone, about half of a first-load document. Behaviour change. The e2e tests now read the script element.
  • Found in QA (auth, existed before this PR): when a session expired during a mutation, the auth middleware stored the mutation's URL as the post-login target, so signing back in did GET /admin/settings/3 and got a 405. Non-GET requests now return to their same-site Referer, with the port checked too, or to no target. A malformed Referer no longer turns the login redirect into a 500.
  • Docs: docs/framework/middleware.md, the CLAUDE.md middleware order line, README, docs/framework-conventions.md, the adapter spec and framework/inertia/README.md (standalone usage).

Verification

  • make lint ✓ · make test-py (8 workers): 7438 passed, 43 skipped ✓ · make test-js: 886 passed ✓
  • e2e suite against a live server (tests/e2e): 49 passed ✓
  • Browser QA (2 iterations):
    • one script[data-page=app] and no data-page on #app; client-side navigation with no full reloads;
    • settings override POST/PUT/DELETE each returned 303 (never 302/307, no 405);
    • a stale or missing version returned 409 with X-Inertia-Location and X-Inertia-Version, and the real version returned 200 JSON;
    • an expired session on a DELETE redirected to login, and sign-in returned to the list page.
    • 1 bug found (the auth target above) and fixed, re-test PASS.
  • Review: two rounds of correctness and maintainability review. Every finding was fixed or rejected with evidence.

https://claude.ai/code/session_01FXHA3ZJ5EgoJN4zXTAhBR2

…e page-object embed (#774, #775, #778)

- A missing X-Inertia-Version counts as "" (mismatch); the version 409 sends
  X-Inertia-Version. Test clients default to the app's current version.
- New InertiaMiddleware (pure ASGI, streaming-safe): 302/307 -> 303 after
  PUT/PATCH/DELETE/QUERY, #fragment redirects -> 409 X-Inertia-Redirect (not on
  prefetch), empty 200 -> 303 back, Vary: X-Inertia. Installed outside module
  middleware so an auth redirect after a DELETE is normalised too.
- The HTML document embeds the page object once (script only; v2 data-page
  attribute dropped).

Claude-Session: https://claude.ai/code/session_01FXHA3ZJ5EgoJN4zXTAhBR2
…middleware-774-778

# Conflicts:
#	CHANGELOG.md
- hold an Inertia 200 only on an explicit Content-Length: 0 (streaming responses
  are never delayed); guard a start message without headers
- the fragment 409 drops headers describing the discarded body (ETag, type, ...)
- one add_vary (simple_module_inertia) shared with hosting's cache middleware
- test helper reuses resolved_version; simple_module_test declares simple_module_inertia
- e2e tests read the script[data-page] element; integration client defaults the
  version header; stale middleware-order docs; #778 marked as a behaviour change

Claude-Session: https://claude.ai/code/session_01FXHA3ZJ5EgoJN4zXTAhBR2
…middleware-774-778

# Conflicts:
#	CHANGELOG.md
#	framework/inertia/README.md
… its Referer

Found by /ship QA on #775: an expired session on an Inertia DELETE now 303s to
the login page, but the DELETE URL was stored as 'next', so signing back in
issued GET /admin/settings/3 -> 405. GET/HEAD navigations keep returning to
themselves; other methods return to the same-site Referer, or nowhere.

Claude-Session: https://claude.ai/code/session_01FXHA3ZJ5EgoJN4zXTAhBR2
- a malformed Referer no longer 500s the login redirect
- same-site check compares the port too (fails closed: no target)

Claude-Session: https://claude.ai/code/session_01FXHA3ZJ5EgoJN4zXTAhBR2
…middleware-774-778

# Conflicts:
#	CHANGELOG.md
#	framework/inertia/simple_module_inertia/errors.py
@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 34c18ea
Status: ✅  Deploy successful!
Preview URL: https://9efb1585.simple-module-python.pages.dev
Branch Preview URL: https://fix-inertia-protocol-middlew.simple-module-python.pages.dev

View logs

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 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-03T19:04:34.903406Z 34c18ea 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 674e534 into main Nov 3, 2026
17 checks passed
@antosubash
antosubash deleted the fix/inertia-protocol-middleware-774-778 branch November 3, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant