motion icon indicating copy to clipboard operation
motion copied to clipboard

SSR doesn't seem to work as intended

Open cerinoligutom opened this issue 4 years ago • 4 comments

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"
}

cerinoligutom avatar Mar 30 '22 21:03 cerinoligutom

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 avatar Apr 01 '22 17:04 Tahul

Could you try @vueuse/[email protected] ?

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

Tahul avatar Sep 11 '22 02:09 Tahul

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

cerinoligutom avatar Oct 05 '22 04:10 cerinoligutom

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.

BobbieGoede avatar Apr 21 '24 12:04 BobbieGoede