Skip to content

Inertia v3 Beta: Native XHR and Optimistic UI Updates

Published: 7 tags 6 min read
Updated:

Inertia v3 Beta transforms the "Modern Monolith" with a native XHR client, optional Axios, and built-in Optimistic UI, effectively bridging the gap between Laravel and standalone SPAs.

The release of the Inertia v3 beta represents a fundamental shift in how we approach the "Modern Monolith." For years, Inertia has been the bridge between server-side routing and client-side rendering, but it often felt one step behind standalone SPAs when it came to ultra-responsive UI patterns. As reported by Laravel News, this new version moves beyond being a simple wrapper, maturing into a robust framework that handles its own HTTP networking and state synchronization.

Inertia v3 Beta: The Evolution of the Modern Monolith

The "Modern Monolith" Milestone

The "Modern Monolith" has always been about productivity—keeping your logic in Laravel while enjoying the reactivity of Vue or React. However, the gap between Inertia and standalone SPAs (like those built with Next.js or Nuxt) was most visible during high-latency interactions. v3 aims to close this gap by introducing features that were previously "opt-in" or required heavy manual lifting, such as optimistic state management and granular request tracking.

Release Context

The beta launch isn't just a feature dump; it’s a re-engineering of Inertia’s core. The mission is clear: improve the developer experience (DX) by reducing boilerplate and boosting performance through a leaner core. By taking control of the network layer, the Inertia team is ensuring that the framework is no longer at the mercy of third-party HTTP client updates or overhead.

Key Pillars

The update rests on two primary pillars: the move to a native XHR client and the introduction of Optimistic UI. These aren't just cosmetic changes; they alter how data flows between the server and the client, allowing for "instant" feeling interfaces that were previously difficult to achieve without breaking the Inertia flow.

The Move to Native XHR and Optional Axios

Decoupling Axios

Historically, Axios was a mandatory dependency for Inertia. While Axios is an industry standard, it added a layer of abstraction that wasn't always necessary for the specific way Inertia handles page transitions and partial reloads. In v3, Axios is now optional. Inertia now ships with its own lightweight, native XHR client.

Architectural Benefits

Moving to a native client allows for tighter integration with Inertia's internal lifecycle. Because the framework now controls the request from initiation to completion, it can more efficiently manage internal state, reduce the overall bundle size, and eliminate the "middleman" overhead. For developers, this means a more predictable networking behavior that is optimized specifically for the "Inertia way."

Backwards Compatibility

The team has been careful not to alienate existing projects. If your application relies on specific Axios interceptors or global configurations, you can still use it. However, the transition to the native client is encouraged for those seeking the best performance and the smallest footprint.

Standardizing Requests

The new native client handles headers, CSRF tokens, and response parsing automatically. This standardization ensures that whether you are performing a simple router.visit or a complex multipart form submission, the behavior is consistent and requires zero manual configuration for standard Laravel setups.

Native Optimistic UI Updates

Closing the SPA Gap

Optimistic UI is the practice of updating the frontend state before the server confirms the request. Think of liking a post: the heart turns red immediately, even if the server takes 200ms to process the request. Previously, doing this in Inertia required manual state management outside of the Inertia props. v3 changes that.

The Implementation Flow

Inertia v3 introduces a way to "optimistically" update props. When a request is triggered, you can define what the expected result will be. Inertia will temporarily patch the page props with your optimistic data while the request is in flight.

router.post('/likes', { id: 5 }, {
    optimistic: {
        props: {
            isLiked: true,
            likesCount: (count) => count + 1,
        }
    }
})

Handling Errors and Rollbacks

The real challenge of Optimistic UI is handling failures. If the server rejects the request (e.g., a 422 validation error or a 500 server error), Inertia v3 automatically rolls back the UI to the previous state. This ensures data integrity without the developer having to write complex "undo" logic for every single interaction.

Real-world Use Cases

This is a game-changer for high-interaction components. Toggles, "Like" buttons, "Add to Cart" actions, and status updates can now feel instantaneous. By eliminating the perceived latency of the round-trip to the server, Inertia apps now feel indistinguishable from highly-tuned standalone SPAs.

The New useHttp Hook

Composable Requests

One of the most exciting additions is the useHttp hook. It brings a modern, reactive approach to data fetching that aligns with the way React and Vue developers expect to work today.

Streamlined Syntax

Instead of relying solely on the global router object, useHttp allows you to manage requests locally within a component. This is particularly useful for actions that don't necessarily need to trigger a full page navigation or change the global loading state.

const { post, processing, errors } = useHttp()

const submit = () => {
    post('/comments', { body: commentBody })
}

Local Request Management

Managing request states (loading, progress, success, and errors) becomes much more granular. Instead of checking a global processing state, you can track the status of a specific button or form section. This localization makes complex interfaces significantly easier to manage and reason about.

Cross-Framework Support

The useHttp API is designed for parity. Whether you are working in React or Vue, the hook functions similarly, providing a unified experience for the Inertia ecosystem. This consistency is a hallmark of Inertia’s design philosophy.

Getting Started and the Road to Stable

How to Install

To jump into the v3 beta, you'll need to update your composer and npm dependencies. For a Vue 3 project, the command typically looks like this:

npm install @inertiajs/vue3@beta
# Or for React
npm install @inertiajs/react@beta

You will also need to ensure your server-side gateway (Inertia-Laravel) is updated to a version that supports the v3 protocol.

Breaking Changes to Watch For

While v3 strives for compatibility, the shift to native XHR and the new hook system may require updates to your middleware and how you handle global events. Specifically, check your HandleInertiaRequests middleware to ensure it aligns with the new requirements for optimistic updates and XHR headers.

The Future of Inertia

Inertia v3 proves that the Laravel/Inertia stack is not just a "simple" alternative to SPAs, but a formidable competitor to frameworks like Next.js. By providing native tools for Optimistic UI and refined HTTP management, Inertia has removed the final few arguments for moving to a decoupled frontend. It reaffirms that for most applications, the Modern Monolith is the most efficient architectural choice.

The transition to v3 marks a maturing of the ecosystem. It is less about "hacking" the server to act like an API and more about a seamless, integrated protocol that understands the needs of modern web interfaces. For intermediate and advanced developers, these changes provide the precision control needed to build world-class user experiences without leaving the comfort of the Laravel ecosystem.