focal icon indicating copy to clipboard operation
focal copied to clipboard

Fix double re-render in LiftWrapper and migrate it to PureComponent

Open KatSick opened this issue 3 years ago • 1 comments

what was done:

  • migrate LiftWrapper to PureComponent
  • move LiftWrapper logic to namespace
  • slight refactor Render{One,Many}
  • eliminate double re-render (because of setState)
  • bonus: added focal bench to https://github.com/krausest/js-framework-benchmark/pull/889

Context

In the previous LiftWrapper, we used setState method to re-render our component when we subscribe to new props AND initially render our component. As an example: during the very first render, we start rendering our renderCache as null and then synchronously re-render it via setState . Since by design Focal does need sync observable emit, I optimized first render to render initial observable value without invoking setState reconciliation (via refs).

todo before merge:

  • [x] add MR description about the issue and the fix (and change title)
  • [x] [not that easy :(]add unit tests for re-renders (currently only renderToStaticMarkup is in unit-tests)
  • [x] [no results] investigate, how to test "waste render" in react via unit-tests (see screenshots)
  • [x] perform benchmarks
  • [x] [it works, but hard to compare values between runs, since they are too small and there is a lot of deviatiosn] investigate elm benchmark

Double re-render fix demo:

Screenshot 2021-07-26 at 11 21 10 Screenshot 2021-07-26 at 11 20 23

https://user-images.githubusercontent.com/13982649/126957306-fbc62a3b-435e-4adf-8301-2ab9b36c6180.mov

KatSick avatar Apr 07 '21 19:04 KatSick

@KatSick benchmark results look awesome! thanks!

@blacktaxi what do you think about those changes? Are we safe to merge it now, or you have any other objections?

Wenqer avatar May 13 '21 10:05 Wenqer