Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nuxt): add experimental View Transitions API support #20092

Merged
merged 11 commits into from Apr 10, 2023

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Apr 4, 2023

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This adds an experimental View Transitions API integration for Nuxt.

You can play around with the implementation in this sandbox or read more about the API.

β„Ή Tips

If you are using Vue transitions to achieve the same result as View Transitions (yes, this is incredibly confusing), then you may wish to disable Vue transitions if the user's browser supports native View Transitions. You can do this by creating ~/middleware/disable-vue-transitions.global.ts with the following contents:

export default defineNuxtRouteMiddleware(to => {
  if (!document.startViewTransition) { return }

  // Disable built-in Vue transitions
  to.meta.pageTransition = false
  to.meta.layoutTransition = false
})

🚨 Known issues

  • View transitions may not work as expected with nested pages/layouts/async components owing to this upstream Vue bug: Nested components in detached branch render while being detachedΒ vuejs/core#5513. If you make use of this pattern, you may need to delay adopting this experimental feature or implement it yourself. Feedback is very welcome.
  • If you perform data fetching within your page setup functions, that you may wish to reconsider using this feature for the moment. (By design, View Transitions completely freeze DOM updates whilst they are taking place.) We're looking at restrict the View Transition to the final moments before <Suspense> resolves, but in the interim you may want to consider carefully whether to adopt this feature if this describes you.

βœ… TODO

I would very much welcome thoughts and improvements even at this stage, but expect that there's some considerable improvement to be made here. In particular, some avenues to explore:

  • See if it's possible to call the route change within startViewTransition, so any errors can be caught there. (This results in a cleaner error handling story and is a nice-to-have but not essential objective.) We can listen to vue errors and throw the promise passed to startViewTransition.
  • Consider whether to disable native Vue page transitions by default when this feature is enabled (setting app.pageTransition to false). Added instructions for how to do this manually, which feels like a better choice.
  • See if we can restrict the transition to the final moments before <Suspense> resolves. The transition completely freezes DOM updates. We therefore don't want it pending while data fetching takes place, so ideally we only want to initiate the transition before the DOM is updated.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codesandbox
Copy link

codesandbox bot commented Apr 4, 2023

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@nuxt-studio
Copy link

nuxt-studio bot commented Apr 4, 2023

βœ… Live Preview ready!

Name Edit Preview Latest Commit
Nuxt Docs Edit on Studio β†—οΈŽ View Live Preview 41ae229

@danielroe danielroe added this to the v3.4 milestone Apr 7, 2023
@danielroe danielroe requested review from Atinux and pi0 April 7, 2023 10:37
@danielroe danielroe marked this pull request as ready for review April 10, 2023 06:52
@danielroe danielroe mentioned this pull request Apr 10, 2023
@danielroe danielroe merged commit e99f923 into main Apr 10, 2023
12 checks passed
@danielroe danielroe deleted the feat/view-transitions branch April 10, 2023 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants