The lifecycle of transitions in Nuxt 3

I have implemented Nuxt 3 layout transitions using JavaScript hooks to smoothly transition between layouts. The transition consists of two parts, one triggered by the onLeave hook and the other triggered by the onEnter hook on the next layout. This setup ensures that users do not see a sudden change in content just before or after the transition.

However, I am facing an issue where the enter hook starts executing before the leave hook completes its operation. Below is the code snippet used in both my templates:

definePageMeta({
  scrollToTop: false,
  layout: "default",
  layoutTransition: {
    name: "layout-transition",
    css: false,
    onLeave: async (el, done) => {
      console.log("leave start")
      await onLeaveAnimation()
      console.log("leave end")
      done()
    },
    onEnter: async (el, done) => {
      console.log("enter start")
      await onEnterAnimation()
      console.log("enter end")
      done()
    }
  },
});

Additionally, here is the output from the console:

leave start
enter start
leave end
enter end

Both transitions utilize GSAP library for animation effects as shown in the following code snippet:

// Inside an asynchronous function
const timeline = gsap.timeline()
const loadingScreen: HTMLElement | null = document.getElementById("loading-screen");
const letters: NodeListOf<Element> | null = document.querySelectorAll(".text-loading-title > span");

const lettersOutAnimation = {
    opacity: 0,
    transform: "translateY(-100%)",
    stagger: 0.05,
    ease: "ease-out",
}

const positionAnimation = {
    transform: "translateY(-100%)",
    duration: 0.5,
    ease: "ease-in-out",
}

const sizeAnimation = {
    height: "0vh",
    duration: 0,
}

await timeline.to(letters, lettersOutAnimation)
await timeline.to(loadingScreen, positionAnimation)
timeline.set(loadingScreen, sizeAnimation)

Answer №1

If you're interested in exploring page transitions in Nuxt3, there's a demo available that utilizes a composable to verify if a transition has been completed:

Feel free to check out the demo here. It may not align perfectly with your requirements, but utilizing the composable method could be beneficial for your specific scenario.

You can also view a similar demo using Vue3 only by visiting this link: here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best method to incorporate a JavaScript object key's value into CSS styling?

I am currently working on a project in React where I'm iterating over an array of objects and displaying each object in its own card on the screen. Each object in the array has a unique hex color property, and my goal is to dynamically set the font co ...

Having trouble with radio button validation in JS?

I'm having difficulty understanding why the radio button is not staying checked when I select another option. To demonstrate, I created a fiddle where initially the "diy" button is selected but switching to "paid" causes the radio button to jump back ...

AngularJs FileList Drag and Drop Feature

Being brand new to front-end development, I decided it would be a fun challenge to implement drag and drop functionality on an existing upload page. However, as I began integrating ng-flow (a directive that helps with drag and drop), I encountered difficul ...

Dealing with an Incorrect Date in JavaScript

After working on a JavaScript logic to extract date and time from certain values, I realized that my approach needed some adjustments. Initially, I parsed the DateTime and converted it to a string. Then, I split the string to retrieve the date component. ...

Oops! Looks like the connection has been abruptly cut off from the ASYNC node

Is there a way to properly close an async connection once all data has been successfully entered? Despite attempting to end the connection outside of the loop, it seems that the structure is being finalized after the first INSERT operation CODE require( ...

Node React authentication

Struggling with implementing authentication in React Router. I am using componentDidMount to check if the user is logged in by calling an endpoint. If not, it should redirect to login, otherwise proceed to the desired component. However, this setup doesn&a ...

JavaScript does not function properly when interacting with the result of a POST request made through $.ajax

Question: After including jQuery files and functions in index.php, do I also need to include them in select.php? To clarify my issue, here is the problem I am facing: Initially, I am trying to send data to select.php using jQuery's $.ajax. The data ...

What is the process of incorporating HTML into a jQuery program in order to immerse the world in an element?

I am looking to utilize HTML with the value in a checkbox, After adding a shortcode: <label class="HCheck">(this is val 1 )</label> and incorporating jQuery to change it to: <label class="HCheck">(this is val 1 ) ...

Combining mouse interactions with animated bar transitions

I want to create a graph with dynamic bar height transitions whenever it is drawn or redrawn. Once the bars are displayed, I would like mouse events (mouseenter, mouseleave, and mousemove) to trigger a tooltip showing information about the specific bar bei ...

The VueJS app seems to be experiencing difficulties with rendering the content

Just starting out with VueJS and I have my initial files - index.html and index.js. I want to stick with just these two files and not add any more. Here's the content of index.html: <html lang="en"> <head> <meta charset ...

Simulating a PubSub publish functionality

I have been trying to follow the instructions provided in this guide on mocking new Function() with Jest to mock PubSub, but unfortunately I am facing some issues. jest.mock('@google-cloud/pubsub', () => jest.fn()) ... const topic = jest.fn( ...

What reasons could lead to useSWR returning undefined even when fallbackData is provided?

In my Next.js application, I'm utilizing useSWR to fetch data on the client-side from an external API based on a specified language query parameter. To ensure the page loads initially, I retrieve data in a default language in getStaticProps and set it ...

What causes Angular to consistently redirect to the homepage?

Whenever I attempt to access the '/' route, it consistently displays the static-root-component (the main page component). However, if I try to access the '/welcome' route, it immediately redirects back to '/' and loads the sta ...

How come attempting to read a nonexistent document from Firestore results in an uncaught promise?

I've been struggling to read and display data from Firestore, but I keep seeing error messages in the console. Encountered (in promise) a TypeError: Unable to read properties of undefined (reading 'ex') Encountered (in promise) a TypeError ...

NG-model not visible to AngularJS Controller's filter

Finally, the code is working perfectly. It's a mystery to me. I created a custom filter to use with ng-repeat. The code is implemented within a Controller ... .controller('makeOrderController', function ($scope, $timeout, $ionicLoading) { ...

A JavaScript variable... cannot access

Can anybody explain to me the reason behind this reference not functioning properly? let linkId = $(this).attr("data-id"); //retrieve the id data when a tag is clicked $(".wrapper").find("section[id=linkId]").css({"background-color": "red"}); ...

Rearranging components in React does not automatically prompt a re-render of the page

I'm currently working on a project to display the update status of my Heroku apps. The issue I encountered was that the parent component (Herokus) was determining the order, but I wanted them sorted based on their update dates starting from the most r ...

Issue encountered while attempting to remove a row from a table (JavaScript)

I'm encountering an error when attempting to delete a table row: "Uncaught ReferenceError: remTable is not defined index.html:1:1". When I inspect index.html to identify the issue, I find this: remTable(this) This is my code: const transact ...

The hyperlink functionality is disabled because Javascript is set to return false

JS Fiddle Example When using the 'FOO' and 'BOO' items in the navigation bar to open dropdown boxes, I have implemented a code that closes them when a click event occurs outside. This code has been working fine as shown below: $(docum ...

Challenges when testing Angular controllers using Jasmine - modular problem

Recently, I made the decision to explore testing my Angular code using Jasmine. While everything seems to work fine without specific dependencies, I encountered problems when there are dependencies involved. For instance, in our project we use controllers. ...