Add defc macro to create fn components with Fast Refresh support by Deraen · Pull Request #598 · reagent-project/reagent · GitHub
Skip to content

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

Draft
Deraen wants to merge 2 commits into
masterfrom
macro-fast-refresh
Draft

Add defc macro to create fn components with Fast Refresh support#598
Deraen wants to merge 2 commits into
masterfrom
macro-fast-refresh

Conversation

@Deraen

@Deraen Deraen commented Dec 1, 2023

Copy link
Copy Markdown
Member

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 Deraen force-pushed the macro-fast-refresh branch from fc86c2a to 6307cc3 Compare December 1, 2023 14:16
@Deraen

Deraen commented Dec 4, 2023

Copy link
Copy Markdown
Member Author

Comment thread doc/ReactRefresh.md
- 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.

Copy link
Copy Markdown

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
Copy Markdown
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.

@Deraen Deraen marked this pull request as draft January 28, 2025 15:11
@Deraen

Deraen commented Jul 25, 2025

Copy link
Copy Markdown
Member Author

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.

2 participants