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

fix(jsx/dom): fix memo for DOM renderer #3568

Merged
merged 4 commits into from
Oct 30, 2024

Conversation

usualoma
Copy link
Member

#3473
#3567

The jsx/dom memoization was generally behaving incorrectly, so I'm fixing it.

12ee829

In the past, the code used the same approach as for toString(), “holding memoized data in JavaScript memory,” but when rendering to the DOM, I found that memoization could be achieved by “not re-evaluate components” in the renderer, so the processing within the renderer was changed accordingly.

Also, looking at the code generated by React Compiler, it seemed that React expected the ReactNode object generated by jsx() to be cached and reused, and to be memoized, so I made it behave in the same way. I applied this branch to the code at https://github.com/sor4chi/explore-react-compiler-with-hono-jsx and confirmed that it was memoized.

38a3c7e / 3b45b57

I changed the implementation of memo so that memoization is done using a new mechanism.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code

Copy link

codecov bot commented Oct 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.72%. Comparing base (7e11832) to head (ff69413).
Report is 12 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3568   +/-   ##
=======================================
  Coverage   94.71%   94.72%           
=======================================
  Files         157      157           
  Lines        9539     9551   +12     
  Branches     2819     2830   +11     
=======================================
+ Hits         9035     9047   +12     
  Misses        504      504           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yusukebe
Copy link
Member

Hi @usualoma

Looks good to me!

@sor4chi Are you interested in reviewing this PR? If so, please!

@yusukebe
Copy link
Member

yusukebe commented Oct 30, 2024

I'll merge this now, though @sor4chi does not review it yet. Thanks!

@yusukebe yusukebe merged commit ea3d799 into honojs:main Oct 30, 2024
16 checks passed
@sor4chi
Copy link
Contributor

sor4chi commented Oct 30, 2024

I was too busy to see it, sorry...
Good test of react-compiler. I could confirm that it is working correctly for me too!

@usualoma usualoma deleted the fix-memoized-state-context branch October 30, 2024 20:45
@usualoma
Copy link
Member Author

@sor4chi Thanks for the review!

TinsFox pushed a commit to TinsFox/hono that referenced this pull request Nov 11, 2024
Fixes honojs#3473
Fixes honojs#3567

* fix(jsx/dom): fix memoization mechanism in dom renderer

* fix(jsx/dom): fix `memo` for DOM renderer

* feat(jsx/dom): implement light weight `memo` function for DOM renderer

* test(jsx/dom): add tests for memoization
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.

3 participants