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

Page transitions bad lifecycle ? #15793

Closed
benjaminrobinet opened this issue Nov 23, 2022 · 3 comments
Closed

Page transitions bad lifecycle ? #15793

benjaminrobinet opened this issue Nov 23, 2022 · 3 comments

Comments

@benjaminrobinet
Copy link

benjaminrobinet commented Nov 23, 2022

Environment

  • Operating System: Darwin
  • Node Version: v18.12.1
  • Nuxt Version: 3.0.0-rc.14
  • Nitro Version: 1.0.0
  • Package Manager: npm@8.19.2
  • Builder: vite
  • User Config: modules, postcss, image, css, vite
  • Runtime Modules: @nuxt/image-edge@1.0.0-27809804.194d2d6
  • Build Modules: -

Reproduction

Just use the javascript hooks of transitions, but here is my use case.

<template>
    <div>
        <NuxtLayout>
            <NuxtPage :transition="transition" />
        </NuxtLayout>
    </div>
</template>

<script setup>
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";

const layoutFooterEl = ref(null);

const transition = {
    mode: 'out-in',
    css: false,
    onLeave: (el, done) => {
        console.log('leave');

        gsap.to([el, layoutFooterEl.value], {
            opacity: 0,
            ease: 'none',
            duration: 0.3,
            onComplete: () => {
                console.log('leave complete');
                done();
            },
        });
    },
    onAfterLeave: () => {
        console.log('after leave');
    },
    onBeforeEnter: (el) => {
        console.log('before enter');

        gsap.set([el, layoutFooterEl.value], { opacity: 0, lazy: false });
    },
    onEnter: (el, done) => {
        console.log('enter');
        gsap.set([el, layoutFooterEl.value], { opacity: 0 });
        viewport.onResize();
        ScrollTrigger.refresh();

        lenis.value.scrollTo(0, { immediate: true });

        gsap.to([el, layoutFooterEl.value], {
            lazy: false,
            opacity: 1,
            ease: 'none',
            duration: 0.7,
            onComplete: done,
        });
    },
};

</script>

Describe the bug

On page transitions, the onMounted() hook is called before the page enter. Here is the lifecycle I have on the page transition:

app.vue:29 leave
page-2.vue:51 mounted
app.vue:34 leave complete
app.vue:44 before enter
app.vue:41 after leave
app.vue:48 enter

UPDATE: Also, the onUnmounted hook is called before the page finished the transition

Additional context

No response

Logs

No response

@benjaminrobinet
Copy link
Author

(Similar to #13471)

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
@maximilliangeorge
Copy link

More relevant info here. This is an up stream bug in Vue. There is a PR claiming to fix this issue but it hasn't been merged for over a year :(

vuejs/core#5952 (comment)

@danielroe
Copy link
Member

Let's track this upstream issue in #13471.

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants