Add Inertia.js API handler -> api.inertia #1906
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
This PR introduces first-class support for Inertia.js endpoints within Encore’s TypeScript runtime by adding a new api.inertia() helper method. This enables Encore applications to serve SSR-friendly single-page applications (SPAs) without leaving the Encore runtime model.
Key Changes:
Dependency Addition
runtimes/js/Cargo.toml
Adds the inertia-rust crate as a dependency to interface with Inertia’s protocol:
New API Helper
runtimes/js/encore.dev/api/mod.ts
Adds api.inertia(), a new helper for defining Inertia-compatible endpoints:
This API allows responding to both traditional page loads and X-Inertia JSON-based SPA transitions, offering a unified pattern for rendering pages server-side and client-side with minimal friction.
Why This Matters:
This addition aligns Encore with modern SSR/SPA architecture practices and makes it straightforward to integrate a frontend powered by Vue/React/Svelte via Inertia.js, without abandoning Encore’s opinionated backend design.
Example Use Case:
The endpoint seamlessly supports both direct HTML entry and client-side navigation with Inertia.