nandorojo / moti

🐼 The React Native (+ Web) animation library, powered by Reanimated 3.
https://moti.fyi
MIT License
3.9k stars 120 forks source link

(Workaround) Next.js without SWC plugin #252

Closed nandorojo closed 1 year ago

nandorojo commented 1 year ago

Making an issue here for visibility.

Workaround

import { enableSwcHack } from 'moti'
enableSwcHack()

Overview

I created a reproduction here of Reanimated not working with SWC: https://github.com/nandorojo/reanimated-next13-issue

Here's the Next.js issue: https://github.com/vercel/next.js/issues/43886 And the Reanimated issue: https://github.com/software-mansion/react-native-reanimated/issues/3971

Expected Behavior

Reanimated should work on Next.js. Due to its architecture, this requires an SWC plugin. However, the plugin is not working.

If you use Reanimated without a plugin, it doesn't break anything, but animations don't usually run. However, On the swc-hack branch, I figured out a way to get Reanimated working on Web without a plugin.

The result will not affect native, only Web (when enabled). The solution adds re-renders to power animations. It shouldn't be noticeable.

Steps To Reproduce

No response

Versions

Next.js 13, Reanimated 2.12.0, Moti `0.21.1-alpha.6`

Screenshots

Screenshot 2023-01-18 at 2 42 34 PM

Reproduction

https://github.com/nandorojo/reanimated-next13-issue

nandorojo commented 1 year ago

Another update is live at 0.21.1-alpha.9, which adds fixes for MotiPressable.

nandorojo commented 1 year ago

Hermes support was pulled in as well.

chrisarts commented 1 year ago

will this bring back the bundle size problem ?

nandorojo commented 1 year ago

It shouldn’t affect that. That all lies in how they tree shake Reanimated

nandorojo commented 1 year ago

I opened a PR to fix this at reanimated once and for all: https://github.com/software-mansion/react-native-reanimated/pull/3997