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

(Workaround) Next.js without SWC plugin #252

Closed
nandorojo opened this issue Jan 19, 2023 · 5 comments
Closed

(Workaround) Next.js without SWC plugin #252

nandorojo opened this issue Jan 19, 2023 · 5 comments

Comments

@nandorojo
Copy link
Owner

nandorojo commented Jan 19, 2023

Making an issue here for visibility.

Workaround

  • yarn add moti@swc (This installs 0.21.1-alpha.6 at the time of writing)

  • Add this at the top of pages/_app.tsx:

import { enableSwcHack } from 'moti'
enableSwcHack()
  • Remove the Reanimated SWC plugin from next.config.js (until it's fixed).

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: vercel/next.js#43886
And the Reanimated issue: software-mansion/react-native-reanimated#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 nandorojo changed the title Next.js 13 + SWC Compatibility (Solved) ReferenceError: i is not defined (Solved) Next.js ReferenceError: i is not defined Jan 19, 2023
@nandorojo nandorojo pinned this issue Jan 19, 2023
@nandorojo nandorojo changed the title (Solved) Next.js ReferenceError: i is not defined (Workaround) Next.js ReferenceError: i is not defined Jan 19, 2023
@nandorojo
Copy link
Owner Author

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

@nandorojo nandorojo changed the title (Workaround) Next.js ReferenceError: i is not defined (Workaround) Next.js without SWC plugin Jan 21, 2023
@nandorojo
Copy link
Owner Author

Hermes support was pulled in as well.

@chrisarts
Copy link

will this bring back the bundle size problem ?

@nandorojo
Copy link
Owner Author

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

@nandorojo
Copy link
Owner Author

I opened a PR to fix this at reanimated once and for all: software-mansion/react-native-reanimated#3997

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

2 participants