Add View Transition API Support to Inertia.js #2421
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.
Add View Transition API Support to Inertia.js
Disclaimer: I was unable to comprehensively test this feature. Some help in testing would be appreciated!
Description
This pull request adds native support for the View Transition API to Inertia.js, enabling smooth animated transitions between page navigations while maintaining the framework's server-driven approach.
Problem Statement
Currently, Inertia.js provides instant page transitions but lacks support for smooth animations between pages. Developers who want animated transitions must implement custom solutions that are complex, error-prone, and don't integrate well with Inertia's visit lifecycle.
Solution
This implementation adds comprehensive View Transition API support through:
Core Changes
New Type Definitions (
packages/core/src/types.ts
)ViewTransitionOptions
interface for configurationVisit
type to includeviewTransition
propertyViewTransitionManager (
packages/core/src/viewTransition.ts
)Router Integration (
packages/core/src/router.ts
)setDefaultViewTransition()
method for global configurationget
,post
,put
,patch
,delete
,visit
) to support view transition optionsResponse Integration (
packages/core/src/response.ts
)Event System (
packages/core/src/events.ts
)inertia:view-transition-start
andinertia:view-transition-end
Benefits to End Users
1. Enhanced User Experience
2. Progressive Enhancement
3. Simple API
4. Flexible Configuration
Backward Compatibility
✅ Fully backward compatible - No breaking changes to existing APIs
✅ Zero impact - Existing applications continue to work without modification
✅ Opt-in - View transitions are disabled by default
Implementation Details
Browser Support Strategy
document.startViewTransition
supportConfiguration Options
enabled
: Boolean to enable/disable transitionsupdateCallback
: Custom callback during transitiononViewTransitionStart
: Called when transition beginsonViewTransitionEnd
: Called when transition completesonViewTransitionError
: Called if transition failsUsage Patterns
Global Configuration:
Per-Visit Configuration:
Framework Integration:
CSS Styling:
Why This Doesn't Break Existing Features
How This Makes Building Web Applications Easier