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

SSR doesn't seem to work as intended #58

Open
Tracked by #81
cerinoligutom opened this issue Mar 30, 2022 · 4 comments
Open
Tracked by #81

SSR doesn't seem to work as intended #58

cerinoligutom opened this issue Mar 30, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@cerinoligutom
Copy link
Contributor

As per docs on SSR Support section, there are 2 options that should work:

<template>
  <div
    v-motion="{
      initial: {
        y: 100,
        opacity: 0
      },
      enter: {
        y: 0,
        opacity: 1
      }
    }"
  >
    Hello
  </div>

  <!-- OR -->

  <div
    v-motion
    :initial="initial"
    :enter="enter"
  >
    Hello
  </div>
</template>

<script setup>
const initial = ref({
  y: 100,
  opacity: 0,
})

const enter = ref({
  y: 0,
  opacity: 1,
})
</script>

The 1st option where we put a stringified object as value on the v-motion directive works. However, the 2nd option where we bind variables to :initial and :enter doesn't work. The latter shows the elements normally and then the animations get applied afterwards. See gif below:

issue demo

That said, the composable usage isn't working either. It seems to behave as if the variables only gets bound on mounted but that doesn't work for SSR.

Additional Context:

This works and I'm getting away with this for the meantime:

<template>
  <div v-motion="motion">Hello</div>
</template>

<script setup>
const motion = {
  initial: {
    y: 100,
    opacity: 0
  },
  enter: {
    y: 0,
    opacity: 1
  }
};
</script>

Versions used:

{
  "nuxt3": "latest",
  "@vueuse/motion": "2.0.0-beta.18"
}
@Tahul
Copy link
Member

Tahul commented Apr 1, 2022

Hello @cerino-ligutom!

Thanks for pointing that out, I have my little idea about why this happens!

Will keep you posted about the fix.

@Tahul Tahul mentioned this issue Sep 11, 2022
13 tasks
@Tahul
Copy link
Member

Tahul commented Sep 11, 2022

Could you try @vueuse/[email protected] ?

Sorry for the last answer, this one is now tracked in #81

@cerinoligutom
Copy link
Contributor Author

Hi @Tahul , thanks for getting back on this. Not using it anymore on my SSR projects as the template got unwieldy with all the animations but would be happy to assist.

I think it's still happening. Check this repro on stackblitz and refresh the web view.

demo_issue

@BobbieGoede
Copy link
Collaborator

I'm not sure if we can make SSR work using the v-motion directive with separate variant props (e.g. :initial, :enter), we can't retrieve the separate props during SSR as the node does not exist yet 🤔.

The usage of passing the variants directly to v-motion allows us to correctly set the node's style during SSR, no existing node is required as the directive is provided all the necessary information.

I think we should probably mention this in the docs, I'll look into the (undocumented?) <Motion> component as well SSR should work without issues for components using the prop usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants