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

how to use sucrase with react-refresh? #590

Open
zcaudate opened this issue Jan 20, 2021 · 2 comments
Open

how to use sucrase with react-refresh? #590

zcaudate opened this issue Jan 20, 2021 · 2 comments

Comments

@zcaudate
Copy link

I'm looking to get react-refresh working with sucrase but I think only babel is supported at the moment:

https://github.com/facebook/react/blob/master/packages/react-refresh/src/ReactFreshBabelPlugin.js

I'm wondering if there have been any attempts to integrate sucrase with the library?

@alangpierce
Copy link
Owner

HI @zcaudate! Unfortunately, react-refresh isn't supported at the moment with Sucrase, and I don't think there have been any attempts yet to implement it. Like with the react-hot-loader transform, I think it's fair to call it in scope for Sucrase, so I'd be happy to accept a PR.

I've looked at the ReactFreshBabelPlugin.js code a few times and there's a lot of logic that may be hard to exactly replicate in Sucrase, especially since Sucrase doesn't have a syntax tree to work with (that's one of the reasons it's so fast). The transform has some heuristics to detect if something is a component or a hook call, so one possible idea is to implement simpler heuristics that are easier to get working in Sucrase.

@zcaudate
Copy link
Author

zcaudate commented Jan 25, 2021

@alangpierce: thanks for responding - and for sucrase. It's such a refreshing change.

I would do it but I just don't have the knowledge right now. I believe react-refresh has it's own diff walking mechanism and it just needs to receive the right inputs from hrm to activate the hook. But I'm missing a lot of context:

  • how webpack.hmr works
  • how sucrase works
  • what react-fast-refresh is actually doing

Because sucrase is so fast, i'm settling on sucrase/react-hot-loader for now.

I did take a look at some gists that was posted for issue that was mentioned on the facebook ticket, the best one being here, I think the babel plugin is doing a lot of babel related stuff and all that is needed is to add this hook to sucrase).

I also had a look at sucrase-hot-reloader that @rickhanlonii linked to and it seems that there shouldn't be that much to change but as I've said before, I'm missing a lot of context.

fhd added a commit to polypoly-eu/polyPod that referenced this issue Jun 17, 2022
Switched from sucrase to babel because it seems that's necessary:
alangpierce/sucrase#590

I also added nollup, because I'm not entirely sure if rollup actually
supports fast refresh natively. Can be invoked with `npm run nollup`.

Doesn't work yet though - building with Babel does, but as soon as the
refresh plugin is being used, it doesn't, neither with nollup nor
rollup.
fhd added a commit to polypoly-eu/polyPod that referenced this issue Jun 17, 2022
Switched from sucrase to babel because it seems that's necessary:
alangpierce/sucrase#590

I also added nollup, because I'm not entirely sure if rollup actually
supports fast refresh natively. Can be invoked with `npm run nollup`.

Doesn't work yet though - building with Babel does, but as soon as the
refresh plugin is being used, it doesn't, neither with nollup nor
rollup.
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