react-slideshow
react-slideshow copied to clipboard
Slideshow broken by Next.js / SWC.rs build process and minification
I came across an odd problem where the slideshow works fine when running Next JS in local development mode, but fails when the site is deployed. I don't think this is a bug in react-slideshow, really, more FYI and reference issue for reporting stuff to SWC project.
The error is
85-ed0064ee95e43d4b.js:formatted:10278 Uncaught ReferenceError: animate is not defined
at v (85-ed0064ee95e43d4b.js:formatted:10278:43)
On inspecting the source, the code surrounding https://github.com/femioladeji/react-slideshow/blob/ec3d13aaad277f0d19cf4bde0eaf696b7b94a8ad/src/fadezoom.tsx#L153-L158 is compiled into this nonsense:
opacity: 0,
scale: 1
};
requestAnimationFrame(animate),
i.current.update();
var g = new P.Tween(e,i.current).to({
Since the const animate = part is "optimised" away, the animate variable passed to requestAnimationFrame is undefined.
The workaround is to set swcMinify: false in next.config.js.
@hallvors thanks for reporting this. I'll look into it and get back to you
@femioladeji Impressive response time and general maintenance of this project. You're amazing 👍 <3
I think it is likely a bug in https://github.com/swc-project/swc but that project has so many open issues and PRs, it is hard to tell if this is reported already :) I tried to copy just some of the code to https://swc.rs/playground and it does not seem broken there - either it is fixed and Next.js is behind on versions, or I didn't include enough code and missed the stuff that actually triggers the bug.