Skip to content

feat(nuxt): add View Transitions Types support#31982

Merged
danielroe merged 7 commits intonuxt:mainfrom
lorenzofiamingo:feat/add-view-transition-types
Feb 26, 2026
Merged

feat(nuxt): add View Transitions Types support#31982
danielroe merged 7 commits intonuxt:mainfrom
lorenzofiamingo:feat/add-view-transition-types

Conversation

@lorenzofiamingo
Copy link
Copy Markdown
Contributor

🔗 Linked issue

Resolves #31972

📚 Description

This PR introduce the possibility to define support for view transition types in the experimental view transitions, as described in the Google View Transition Update.

#31972 (comment)

Normally we try to avoid passing functions from nuxt config -> runtime code.

Maybe instead we could have a hook that allows users to configure this at runtime instead? For example, we currently have this one that allows access to the transition:

nuxt/packages/nuxt/src/app/plugins/view-transitions.client.ts

Line 60 in b74f2a6

await nuxtApp.callHook('page:view-transition:start', transition)

I haven’t implemented the hook approach. If feasible, we should definitely move in that direction to better align with Nuxt’s conventions and avoid passing functions from config to runtime.

@lorenzofiamingo lorenzofiamingo requested a review from danielroe as a code owner May 2, 2025 16:26
@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions bot added the 3.x label May 2, 2025
@lorenzofiamingo lorenzofiamingo changed the title add view transitions types support feat(nuxt): add view transitions types support May 2, 2025
@lorenzofiamingo lorenzofiamingo changed the title feat(nuxt): add view transitions types support feat(nuxt): add View Transitions Types support May 2, 2025
@lorenzofiamingo lorenzofiamingo marked this pull request as draft May 2, 2025 16:28
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented May 2, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@31982

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@31982

nuxt

npm i https://pkg.pr.new/nuxt@31982

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@31982

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@31982

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@31982

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@31982

commit: 2592105

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 2, 2025

Walkthrough

The pull request introduces support for view transition types in the experimental View Transitions API. It adds new ViewTransitionOptions and ViewTransitionPageOptions type definitions that support configurable transition types through static arrays or dynamic functions. The plugin implementation is updated to resolve these types at runtime based on route information and pass them to the View Transitions API. Configuration schemas are updated to accept the new object-based configuration structure. Documentation is added across multiple files explaining the feature, including code examples for global and per-page configurations. The changes maintain backward compatibility with existing boolean or 'always' configurations.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately summarizes the main change: adding View Transitions Types support to Nuxt.
Description check ✅ Passed The PR description clearly relates to the changeset, explaining the feature implementation and referencing the linked issue with relevant context.
Linked Issues check ✅ Passed The PR implements View Transitions Types support with ViewTransitionOptions configuration, types resolution in the plugin, and updated documentation, addressing all core coding requirements from issue #31972.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing View Transitions Types support as specified in issue #31972; documentation updates and type definitions are appropriately scoped.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
docs/3.api/3.utils/define-page-meta.md (1)

117-121: ⚠️ Potential issue

Documentation text doesn't match the updated type definition

While the type in the interface has been updated to ViewTransitionPageOptions['enabled'] | ViewTransitionPageOptions, the documentation still describes it as boolean | 'always'. This could be confusing for users trying to implement the enhanced view transition options.

Apply this diff to update the documentation:

- **Type**: `boolean | 'always'`
+ **Type**: `boolean | 'always' | ViewTransitionPageOptions`

Add a brief explanation about the expanded capabilities:

If set to true, Nuxt will not apply the transition if the users browser matches `prefers-reduced-motion: reduce` (recommended). If set to `always`, Nuxt will always apply the transition. Alternatively, you can provide a `ViewTransitionPageOptions` object to specify transition types for more granular control.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~121-~121: It looks like there might be a possessive apostrophe missing. Consider inserting it.
Context: ...xt will not apply the transition if the users browser matches `prefers-reduced-motion...

(AI_EN_LECTOR_MISSING_NOUN_POSSESSIVE)

🧹 Nitpick comments (3)
packages/nuxt/src/app/plugins/view-transitions.client.ts (1)

67-78: Optional: remove @ts-expect-error by widening lib types instead

Using // @ts-expect-error hides legitimate typing mistakes. Consider type-augmenting document.startViewTransition instead, so the extra update/types properties are recognised:

declare global {
  interface Document {
    startViewTransition(init?: {
      update?: () => Promise<void>
      types?: string[]
    }): ViewTransition
  }
}

This keeps IntelliSense and build-time safety intact.

packages/schema/src/types/config.ts (2)

166-169: Naming convention might cause confusion.

The toTypes and fromTypes properties combined with the function signature (to, from) => [string] could be confusing. Consider adding a documentation comment clarifying that:

  • toTypes specifies transition types when navigating to the page (with this configuration)
  • fromTypes specifies transition types when navigating away from the page (with this configuration)

This would prevent misunderstanding when implementing these functions.

 export interface ViewTransitionPageOptions extends ViewTransitionOptions {
+  /**
+   * Specifies transition types applied when navigating TO this page.
+   * In the function signature, 'to' refers to the route being navigated to.
+   */
   toTypes?: [string] | ((to: RouteLocationNormalizedGeneric, from: RouteLocationNormalizedGeneric) => [string])
+  /**
+   * Specifies transition types applied when navigating FROM this page.
+   * In the function signature, 'from' refers to the route being navigated from.
+   */
   fromTypes?: [string] | ((to: RouteLocationNormalizedGeneric, from: RouteLocationNormalizedGeneric) => [string])
 }

161-164:

Details

❓ Verification inconclusive

Consider clarifying the types property definition.

The types property is defined as [string] (a tuple with exactly one string), which seems restrictive. If multiple transition types are supported, consider using string[] instead for flexibility.


🏁 Script executed:

#!/bin/bash
# Check how view transition types are used in the implementation
grep -r "types.*\[string\]" --include="*.ts" --include="*.vue" packages/
grep -r "startViewTransition.*types" --include="*.ts" --include="*.vue" packages/

Length of output: 304


Verify tuple vs. array for types in ViewTransitionOptions

The current definition in packages/schema/src/types/config.ts enforces a single-element tuple ([string]), which may be too restrictive if multiple transition types are supported. No references to this interface or its types field were found elsewhere in the codebase, so please confirm whether the tuple is intentional or should be widened to an array.

• File: packages/schema/src/types/config.ts (lines 161–164)

-export interface ViewTransitionOptions {
-  enabled: boolean | 'always'
-  types?: [string] | ((to: RouteLocationNormalizedGeneric, from: RouteLocationNormalizedGeneric) => [string])
-}
+export interface ViewTransitionOptions {
+  enabled: boolean | 'always'
+  types?: string[] | ((to: RouteLocationNormalizedGeneric, from: RouteLocationNormalizedGeneric) => string[])
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da97ec7 and 29bf885.

📒 Files selected for processing (8)
  • docs/1.getting-started/09.transitions.md (2 hunks)
  • docs/3.api/3.utils/define-page-meta.md (1 hunks)
  • packages/nuxt/src/app/plugins/view-transitions.client.ts (4 hunks)
  • packages/nuxt/src/pages/module.ts (1 hunks)
  • packages/schema/src/config/app.ts (2 hunks)
  • packages/schema/src/config/experimental.ts (1 hunks)
  • packages/schema/src/types/config.ts (2 hunks)
  • packages/schema/src/types/schema.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/nuxt/src/app/plugins/view-transitions.client.ts (1)
packages/schema/src/types/config.ts (2)
  • ViewTransitionPageOptions (166-169)
  • ViewTransitionOptions (161-164)
packages/schema/src/types/schema.ts (1)
packages/schema/src/types/config.ts (1)
  • ViewTransitionOptions (161-164)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: test-fixtures (windows-latest, built, vite, async, manifest-on, json, 20)
  • GitHub Check: test-fixtures (windows-latest, built, rspack, async, manifest-on, json, 20)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-off, json, 20)
  • GitHub Check: test-fixtures (windows-latest, built, webpack, async, manifest-on, json, 20)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-off, json, 20)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-off, json, 20)
  • GitHub Check: test-fixtures (windows-latest, built, vite, async, manifest-off, json, 20)
  • GitHub Check: test-fixtures (windows-latest, built, vite, default, manifest-off, json, 20)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-on, json, 20)
  • GitHub Check: test-benchmark
  • GitHub Check: test-size
  • GitHub Check: release-pr
  • GitHub Check: typecheck (ubuntu-latest, bundler)
  • GitHub Check: typecheck (windows-latest, bundler)
  • GitHub Check: lint-docs
  • GitHub Check: code
🔇 Additional comments (10)
docs/3.api/3.utils/define-page-meta.md (1)

37-37: Update type definition for viewTransition

The type definition for the viewTransition property has been updated to support the more flexible ViewTransitionPageOptions type system. This enhancement allows for more granular control over view transitions, including specifying transition types.

packages/schema/src/config/experimental.ts (1)

229-229: Updated viewTransition type annotation

The type annotation for the experimental viewTransition option has been expanded to support the more flexible ViewTransitionOptions type system. This allows users to either specify just the enabled state or provide a complete configuration object with transition types.

docs/1.getting-started/09.transitions.md (2)

434-435: Added documentation for ViewTransitionOptions

Excellent addition explaining the new capability to provide a ViewTransitionOptions object for specifying View Transition Types. This aligns perfectly with the code changes and helps users understand the enhanced functionality for implementing asymmetric transitions.


449-450: Added documentation for ViewTransitionPageOptions

Good explanation of how ViewTransitionPageOptions can be used to override or add View Transition Types for specific pages. This completes the documentation for the new view transitions type support feature.

packages/nuxt/src/pages/module.ts (2)

646-646: Added import for ViewTransitionPageOptions type

Added import for the ViewTransitionPageOptions type from the config types, which is necessary for the updated page meta type definition.


649-649: Updated viewTransition type in PageMeta

The type definition for viewTransition in PageMeta has been updated to use the more flexible ViewTransitionPageOptions type, providing consistency with the updated configuration options throughout the codebase.

packages/schema/src/types/schema.ts (1)

37-38: View-transition type integration looks correct

The new import and the refined experimental.viewTransition union cleanly hook the richer ViewTransitionOptions into the global schema without breaking the existing boolean/'always' contract.
Nice job keeping backwards compatibility while enabling the new feature set.

Also applies to: 1246-1247

packages/schema/src/config/app.ts (1)

226-247: Return type is always fully resolved – good defensive coding

The resolver now normalises enabled and types, merging app-level and experimental defaults in a single place.
It also guarantees an enabled value even when nothing is configured ({ enabled: false } fallback), so downstream code can rely on its presence.
Solid improvement.

packages/schema/src/types/config.ts (2)

9-9: Import added correctly.

The addition of the RouteLocationNormalizedGeneric type import from vue-router is appropriate, as it's required for the new type definitions related to view transitions.


153-153: Type enhancement for viewTransition is well-structured.

The viewTransition property type has been enhanced from a simple boolean to support the new options pattern. This provides both backward compatibility (through ViewTransitionOptions['enabled']) and the ability to use the full options object.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented May 2, 2025

Merging this PR will not alter performance

✅ 20 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing lorenzofiamingo:feat/add-view-transition-types (2592105) with main (873c77b)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

…ion-types

# Conflicts:
#	docs/1.getting-started/09.transitions.md
#	docs/2.guide/3.going-further/1.experimental-features.md
#	packages/nuxt/src/app/plugins/view-transitions.client.ts
#	packages/schema/src/config/app.ts
#	packages/schema/src/config/experimental.ts
#	packages/schema/src/types/config.ts
#	packages/schema/src/types/schema.ts
@danielroe danielroe marked this pull request as ready for review February 26, 2026 09:47
Copy link
Copy Markdown
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goodness, I'm sorry this took so long! but thank you - this is great ❤️

@danielroe danielroe enabled auto-merge February 26, 2026 09:48
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
docs/3.guide/6.going-further/1.experimental-features.md (1)

324-326: Clarify the second read-more block to differentiate it from the first.

Both read-more blocks use identical text ("Read more about the View Transition API") but link to different resources. The first links to MDN's general API documentation, whilst the second links to Chrome's blog post specifically about view transition types. This could confuse readers who might skip the second link thinking it's a duplicate.

📝 Suggested text change
-::read-more{icon="i-simple-icons-google" to="https://developer.chrome.com/blog/view-transitions-update-io24" target="_blank"}
-Read more about the **View Transition API**.
-::
+::read-more{icon="i-simple-icons-google" to="https://developer.chrome.com/blog/view-transitions-update-io24" target="_blank"}
+Read more about **View Transition Types** in the Chrome update.
+::
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/3.guide/6.going-further/1.experimental-features.md` around lines 324 -
326, The second ::read-more block currently duplicates the text "Read more about
the **View Transition API**" while pointing to a different URL; update its text
to clearly indicate the specific resource (for example "Read Chrome's blog post
on View Transition types") so readers know it links to the Chrome I/O article
rather than the general MDN doc, and keep the
::read-more{icon="i-simple-icons-google"
to="https://developer.chrome.com/blog/view-transitions-update-io24"
target="_blank"} attributes unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@docs/3.guide/6.going-further/1.experimental-features.md`:
- Around line 324-326: The second ::read-more block currently duplicates the
text "Read more about the **View Transition API**" while pointing to a different
URL; update its text to clearly indicate the specific resource (for example
"Read Chrome's blog post on View Transition types") so readers know it links to
the Chrome I/O article rather than the general MDN doc, and keep the
::read-more{icon="i-simple-icons-google"
to="https://developer.chrome.com/blog/view-transitions-update-io24"
target="_blank"} attributes unchanged.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 29bf885 and 2592105.

📒 Files selected for processing (3)
  • docs/1.getting-started/09.transitions.md
  • docs/3.guide/6.going-further/1.experimental-features.md
  • docs/4.api/3.utils/define-page-meta.md

@danielroe danielroe added this pull request to the merge queue Feb 26, 2026
Merged via the queue into nuxt:main with commit 34787e4 Feb 26, 2026
56 of 57 checks passed
@github-actions github-actions bot mentioned this pull request Feb 26, 2026
This was referenced Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add types support to View Transitions

2 participants