Skip to content

Implement inertia - #1

Open
proudhAteR wants to merge 11 commits into
ophelios-studio:devfrom
proudhAteR:implement-inertia
Open

Implement inertia#1
proudhAteR wants to merge 11 commits into
ophelios-studio:devfrom
proudhAteR:implement-inertia

Conversation

@proudhAteR

Copy link
Copy Markdown

This PR adds Inertia.js protocol support (POC) to Zephyrus, allowing controllers to return modern frontend views directly from the backend:

#[Get('/inertia')]
public function demo(): Response
{
    return $this->inertia('Home', [
            'title' => 'Zephyrus x Inertia',
            'message' => 'A server-driven Vue experience hydrated by PHP props.',
            'phpVersion' => PHP_VERSION,
    ]);
}

How does it work

The first request renders an HTML shell, and subsequent Inertia requests receive the JSON page object used by the frontend adapter to render the right component with the right
props.

Why this is pertinent

Zephyrus already owns routing, controllers, middleware, validation, sessions, and rendering. Inertia fits that model well because it lets applications keep server-side routing and
data loading while using React, Vue, or Svelte for the view layer.

This avoids forcing users to build and maintain a separate API just to power client-rendered screens. It keeps Zephyrus applications closer to a server-driven monolith while still
enabling rich frontend interactivity.

What changed

  • Added an Inertia renderer, facade, middleware, and root view helpers.
  • Added controller support through $this->inertia(...).
  • Added ApplicationBuilder::withInertia() and withInertiaRenderer().
  • Exposed the current request during kernel dispatch so Inertia responses can inspect headers, method, URL, and asset version.
  • Added inertia_app() and inertia_head() helpers for the root PHP shell.
  • Added Vite rendering support through vite().
  • Added production manifest support for Vite assets.
  • Added development-server support for Vite entrypoints.
  • Updated Composer requirements:
    • PHP requirement moved from ^8.4 to ^8.5.
    • Added maskulabs/inertia-psr:^3.0.

Why Vite is needed

Inertia still needs a frontend entrypoint to boot the client adapter and resolve components. Vite gives Zephyrus applications a standard way to serve those frontend assets:

  • In development, Zephyrus can point the HTML shell at the Vite dev server and load the Vite client.
  • In production, Zephyrus can read the Vite manifest and render the hashed JS/CSS assets generated by vite build.
  • This also aligns with Inertia asset-versioning behavior, where stale frontend assets can trigger a full-page reload instead of returning incompatible JSON payloads.

Inertia protocol coverage

Implemented in this PR:

  • Initial full-page HTML shell response.
  • Inertia JSON responses for X-Inertia: true requests.
  • Core page object shape: component, props, url, and version.
  • Default errors prop.
  • Shared props.
  • Vary: X-Inertia handling.
  • Partial reloads with:
    • X-Inertia-Partial-Component
    • X-Inertia-Partial-Data
    • X-Inertia-Partial-Except
  • Asset version mismatch handling with 409 Conflict and X-Inertia-Location.
  • External location redirects through the Inertia protocol.
  • 302 to 303 redirect conversion after PUT, PATCH, and DELETE Inertia requests.
  • Root view helpers for mounting the app and rendering title metadata.

Not included in this first pass / possible follow-ups:

  • SSR support.
  • Deferred props.
  • Merge, prepend, deep-merge, scroll, and once props.
  • History encryption / clearing.
  • Fragment redirect support via X-Inertia-Redirect.
  • Error bags and advanced validation-specific Inertia headers.

Test coverage

Added focused unit coverage for the Inertia and Vite layers, including renderer behavior, middleware behavior, facade behavior, root view helpers, partial reloads, version
conflicts, redirects, Vite development tags, Vite production manifest loading, and Vite error cases.

Current coverage after this PR:

  • Whole app:
    • Classes: 68.38%
    • Methods: 88.70%
    • Lines: 95.44%
  • Inertia namespace:
    • Inertia: 94.44% line coverage
    • InertiaMiddleware: 100%
    • InertiaRenderer: 98.82%
    • InertiaView: 100%
  • Vite integration:
    • Vite: 96.60%
    • ViteException: 100%

Verification

composer test
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text --colors=never

Result:

  • 2288 tests
  • 4818 assertions
  • Passing on PHP 8.5.6
  • Existing runner output still reports 1 deprecation, 6 PHPUnit deprecations, and 2 skipped tests.

Demo app

Created a demo Vue component to showcase what can be done using this integration (The whole component has been vibe coded)
https://github.com/proudhAteR/Zephyrus_Inertia_demo

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