feat(nuxt): add View Transitions Types support#31982
Conversation
|
|
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
WalkthroughThe pull request introduces support for view transition types in the experimental View Transitions API. It adds new 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
docs/3.api/3.utils/define-page-meta.md (1)
117-121:⚠️ Potential issueDocumentation 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 asboolean | '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-errorby widening lib types insteadUsing
// @ts-expect-errorhides legitimate typing mistakes. Consider type-augmentingdocument.startViewTransitioninstead, so the extraupdate/typesproperties 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
toTypesandfromTypesproperties combined with the function signature(to, from) => [string]could be confusing. Consider adding a documentation comment clarifying that:
toTypesspecifies transition types when navigating to the page (with this configuration)fromTypesspecifies 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
typesproperty is defined as[string](a tuple with exactly one string), which seems restrictive. If multiple transition types are supported, consider usingstring[]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
typesin ViewTransitionOptionsThe current definition in
packages/schema/src/types/config.tsenforces a single-element tuple ([string]), which may be too restrictive if multiple transition types are supported. No references to this interface or itstypesfield 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
📒 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 viewTransitionThe type definition for the
viewTransitionproperty has been updated to support the more flexibleViewTransitionPageOptionstype 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 annotationThe type annotation for the experimental
viewTransitionoption has been expanded to support the more flexibleViewTransitionOptionstype 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 ViewTransitionOptionsExcellent addition explaining the new capability to provide a
ViewTransitionOptionsobject 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 ViewTransitionPageOptionsGood explanation of how
ViewTransitionPageOptionscan 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 typeAdded import for the
ViewTransitionPageOptionstype from the config types, which is necessary for the updated page meta type definition.
649-649: Updated viewTransition type in PageMetaThe type definition for
viewTransitionin PageMeta has been updated to use the more flexibleViewTransitionPageOptionstype, providing consistency with the updated configuration options throughout the codebase.packages/schema/src/types/schema.ts (1)
37-38: View-transition type integration looks correctThe new import and the refined
experimental.viewTransitionunion cleanly hook the richerViewTransitionOptionsinto 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 codingThe resolver now normalises
enabledandtypes, merging app-level andexperimentaldefaults in a single place.
It also guarantees anenabledvalue 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
RouteLocationNormalizedGenerictype 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.
Merging this PR will not alter performance
Comparing Footnotes
|
…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
left a comment
There was a problem hiding this comment.
goodness, I'm sorry this took so long! but thank you - this is great ❤️
There was a problem hiding this comment.
🧹 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
📒 Files selected for processing (3)
docs/1.getting-started/09.transitions.mddocs/3.guide/6.going-further/1.experimental-features.mddocs/4.api/3.utils/define-page-meta.md
🔗 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)
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.