darkroomengineering / lenis

How smooth scroll should be

Home Page:https://lenis.darkroom.engineering

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot read private member from an object whose class did not declare it

benoitdelorme opened this issue · comments

Describe the bug
I use Lenis in my Nuxt3-Lenis module and since I updated with the latest version of Lenis I have an error when I'm using lenis.start() and lenis.stop(). It worked with version 1.0.27

Capture d’écran, le 2024-02-15 à 08 03 45

I tried to fix it but without much success.

start() {
  this.isStopped = false //  this.#isStopped = false
  this.reset()
}

stop() {
  this.isStopped = true //  this.#isStopped = true
  this.animate.stop()

  this.reset()
}

You mean calling lenis.start() throws this error ? Can you provide a codesandbox ? It seems you're trying to change a private property of Lenis.

It might comes from how you use Lenis in your implementation since it works as expected here https://codesandbox.io/p/sandbox/small-cdn-yk9cqy?file=%2Fsrc%2FApp.js%3A8%2C16

i have the same problem. It happens when i call the functions start() and stop()

I can't access your codesandbox @plcdnl

image

I'm facing the same issue when calling start() and stop(). It seems to happen from Lenis v1.0.35, because v1.0.34 works fine on my end.

I think it comes from this commit, where private properties have been introduced.

According to the MDN Docs about Private Fields, I would suggest accessing these private class properties using this.#isStopped instead of this.isStopped for example : https://github.com/darkroomengineering/lenis/blob/main/packages/lenis/src/index.ts#L276

(I'm using Nuxt 3.10.2)

Why is this happening only with nuxt ?

Good question, have you tested it in a vanilla js environment ?

Why is this happening only with nuxt ?

https://codesandbox.io/p/devbox/lenis-nuxt-bug-tfdzlp

here the sandbox. Sorry!

I can't access your sandbox either @clementroche

image

It seems like codesandbox make draft private by default now

here is @thiervoj : https://codesandbox.io/p/sandbox/small-cdn-yk9cqy?file=%2Fsrc%2FApp.js

can you try outside of defineNuxtPlugin ?

can you try outside of defineNuxtPlugin ?

https://codesandbox.io/p/devbox/lenis-nuxt-bug-forked-9kkc6c?

Ok found, it happens with vue reactive/refs. With simple vars it works without problems

ok that's not ideal anyway, thank you for your feedback, I must find a better way to handle it imo. Imma revert to previous way.

Thank you for your work!

Thank you!

It's fixed in v1.0.37