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

Next Js 13.5 Effects are not being rendered #221

Closed
AmanAdastra opened this issue Sep 21, 2023 · 16 comments
Closed

Next Js 13.5 Effects are not being rendered #221

AmanAdastra opened this issue Sep 21, 2023 · 16 comments

Comments

@AmanAdastra
Copy link

AmanAdastra commented Sep 21, 2023

Support

Hi there,

I followed the official docs and implemented the same in with latest version but unable to get it work,

I am wondering where to put the ParallaxProvider?

import './globals.css'
import { Inter } from 'next/font/google'

import './globals.css'
import { Inter } from 'next/font/google'

import ParallexProviderComponent from '@/components/ParallexProviderComponent'

const inter = Inter({ subsets: ['latin'] })

export const metadata = {
  title: 'Create Next App',
  description: 'Generated by create next app',
}

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body className={inter.className}>
        ParallexProviderComponent
        {children}
        ParallexProviderComponent
      </body>
    </html>
  )
}

This is not working

@Fisico
Copy link

Fisico commented Sep 21, 2023

I can confirm that nextjs 13.5 broke the parallax effect. The transforms are not updating and always stay on the initial value.
<div class="container" style="will-change: transform; transform: translateY(-52.9394px);">

Worked flawless in 13.4.

@DottChen
Copy link

DottChen commented Sep 22, 2023

Worked flawless in 13.4.

Which version of 13.4. is working? I'm using 13.4.19 and the transforms are also broken. The value stays unchanged when scrolling. Thank you.

@Fisico
Copy link

Fisico commented Sep 22, 2023

Worked flawless in 13.4.

Which version of 13.4. is working? I'm using 13.4.19 and the transforms are also broken. The value stays unchanged when scrolling. Thank you.

I have 13.4.19 running. works fine.
<Parallax speed={-30} className="row"> is what i use in a "use client"; component.

@DottChen
Copy link

Just downgraded to 13.4.1 and worked well for me. Thanks anyway!

@jscottsmith
Copy link
Owner

jscottsmith commented Sep 23, 2023

@Fisico Is correct -- it seems that using the app directory in Next 13.5 prevents scroll effects.

Reproduction repo: https://github.com/jscottsmith/react-scroll-parallax-next-13-bug

Also confirming that downgrading to next: 13.4.19 seems to fix the issue.

Unclear what this issue is so far, I will look into this further.

@pepijn-vanvlaanderen
Copy link

We have the same issue, a workaround we applied is to set scroll listener ourselves, i.e. that would be:

const passiveEventListener: AddEventListenerOptions = { passive: true }
const FixParallaxScrollEvent = () => {
    const parallaxController = useParallaxController()

    useEffect(() => {
        if (parallaxController) {
            const updateParallaxController = () => parallaxController.update()

            window.addEventListener("scroll", updateParallaxController, passiveEventListener)

            return () => {
                window.removeEventListener("scroll", updateParallaxController, passiveEventListener)
            }
        }
    }, [parallaxController])

    return null
}

const ParallexProviderComponent = ({ children }) => {
    return (
        <ParallaxProvider>
            <FixParallaxScrollEvent />
            {children}
        </ParallaxProvider>
    )    
}

@AmanAdastra
Copy link
Author

AmanAdastra commented Sep 27, 2023

@jscottsmith To Natively Support the above Crash are u working on the fix or should the users do workaround for Now?

@jscottsmith
Copy link
Owner

I would stick to next@13.4.x for now as this issue seems caused by Next. If an update is required in this lib, PR's are welcome.

I would not do as @pepijn-vanvlaanderen suggests because calling update() will break cache on every scroll event and could cause jank.

@jscottsmith
Copy link
Owner

For clarity, this issue only occurs in development -- npm run dev with NextJS

If you run npm run build && npm run start to run a production build parallax works as expected.

@AmanAdastra
Copy link
Author

@jscottsmith Thanks for your response!!, I did raise the issue on Next Repo but have yet to get a comment, I am marking the Issue Closed here.
Also thanks to @pepijn-vanvlaanderen @DottChen @Fisico for involvement.
Have a Good Day!!

@IanBoyte
Copy link

IanBoyte commented Oct 6, 2023

Shouldn't this issue remain open for visibility until there's a resolution either on the next.js or react-scroll-parallax side?
Also thanks to @pepijn-vanvlaanderen for that workaround.

@AmanAdastra
Copy link
Author

Okay Let me open this for the Community, it can save Endless hours.

@AmanAdastra AmanAdastra reopened this Oct 10, 2023
@jscottsmith jscottsmith removed the bug label Oct 10, 2023
@jscottsmith
Copy link
Owner

jscottsmith commented Oct 10, 2023

Reiterating —

This is a dev only issue in Next JS. If you run npm run build && npm run start to run a production build parallax effects will works as expected.

DO NOT add your own scroll event listener and call parallaxController.update(). This will cause performance issues.

Stick to next@13.4.x

@AmanAdastra
Copy link
Author

Agreed @jscottsmith Next 13.5 is Mess, Hot Module Reload Stopped Working. Hope they resolve this major issues or allow us to mention the version while creating the next project using npx create-next-app@version

@jscottsmith
Copy link
Owner

Please try v3.4.4 to see if this issue is resolved.

@AmanAdastra
Copy link
Author

Okay I am Closing this issue because latest version fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants