Jump to content
Search Community

ScrollTrigger & Nuxt - Error on when component update

Simon.Gioffredi test
Moderator Tag

Go to solution Solved by Simon.Gioffredi,

Recommended Posts

Hi,

 

First of all, sorry for my english, I'm not an english native speaker.

 

I have an issue when I use ScrollTrigger and Nuxt.

https://codesandbox.io/s/scrolltrigger-nuxt-update-component-wlo2y

 

You can see the demo here.

When we reload, or come for the first time in the page, there is no problem.

But if you make Nuxt reload the component, you can see an error appear.

If you change the console.log, you can see the WebApp updates, and there is a bug who appear.
 

Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.

 

The bug only appear when you pin the element.

 

I understand the problem, that's the trigger we pass to ScrollTrigger which isn't good, but I don't understand why.

 

Does anyone has an idea ?

 

Thx :)
 

Link to comment
Share on other sites

Hi Cassie,

 

In the Nuxt lyfecicle, when you change something in your component, only the component "update".

When you arrive on the project, everything works fine, but when you update your component (for example, change the console.log), the component should update, and here, there is an error.

 

Link to comment
Share on other sites

Also noticed you importing like this.

import { ScrollTrigger } from "gsap/dist/ScrollTrigger.min.js";

 

You can simplify that by adding this to your nuxt.config.js file.

build: {
  transpile: [
    "gsap"
  ]
}

 

Now you should be able to import like this.

import { ScrollTrigger } from "gsap/ScrollTrigger";

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 10 months later...

I was running into issues like this with HMR as well as in other cases where a change in props to a Vue component resulted in the component being destroyed and recreated.  What worked for me was to switch not use `pin: true`.  In other words, separate the trigger and the pin.  So my markup, now, is kind of like:

 

<div class='component'>
  <div class='pin'></div>
</div>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...