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

Add defc macro to create fn components with Fast Refresh support #598

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Deraen
Copy link
Member

@Deraen Deraen commented Dec 1, 2023

Investigating if React Refresh support is possible in some way. It will require using a macro, because attaching necessary data to the function (component) just isn't possible when components are created when rendering Hiccup forms (what Reagent normally does.)

  • Target is to get React Refresh working
  • Working React Refresh will allow better dev experience on a project transitioning from Reagent to UIx/Helix
  • As a side-effect this will create function components which work without :f>
  • Macro to handle Hiccup or properties transform is not a target (one could probably wrap the macro with Sablono to do that)
  • Seems like Refresh works for "old" components being used from defc component also! No need to convert everything to use the macro?
    • It is possible that one old type component will force sub-tree re-mount which prevents keeping Hooks state for anything under that component?? Need to test.
  • Does setting forceReset flag cause re-mount always? If so, we might HAVE to create correct signatures to keep state for even UIx components in component tree?

TODO:

  • Looks like form-2 components don't work
  • Form-3 not tested, not sure if makes even sense
  • Check if we could create real Hook signature now that we have macro which can analyze the code (-> keep hook state over reloads if signature doesn't change)

@Deraen
Copy link
Member Author

Deraen commented Dec 4, 2023

TODO: Controlled inputs don't work inside defc / or just dereferencing ratoms values.

- Call `reagent.dev/refresh!` instead
- Only components defined using `r/defc` will refresh
- Reagent doesn't try to create Hook signatures for components,
so hook state is reset for updated components.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m curious, if local state will be reset, what’s the motivation to enable react refresh in Reagent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To help projects using both Reagent and UIx/Helix, so they can enable it and get benefit on React Refresh for UIx/Helix components.

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

Successfully merging this pull request may close these issues.

None yet

2 participants