Skip to content

fix(cacheable-section): stable references to avoid loops [LIBS-642]#1385

Merged
KaiVandivier merged 3 commits intomasterfrom
libs-642-stable-references-for-cacheable-sections
Jul 26, 2024
Merged

fix(cacheable-section): stable references to avoid loops [LIBS-642]#1385
KaiVandivier merged 3 commits intomasterfrom
libs-642-stable-references-for-cacheable-sections

Conversation

@KaiVandivier
Copy link
Copy Markdown
Contributor

@KaiVandivier KaiVandivier commented Jul 18, 2024

Implements LIBS-642

These hooks were implemented unoptimally, admittedly, and functions were getting recreated on each render. This caused issues if they were used as dependencies for useEffect hooks, like an infinite loop demoed below

I've updated the hooks to use best practices with useCallback and useMemo to make stable references and minimize unnecessary rerenders, and I added some automated tests to help verify the stability -- the tests look simplistic, but they were failing before the changes, and actually helped track down which hooks were still unstable in a TDD way

I also tested manually with the PWA example app in the App Platform, with some code that looks like an implementation in analytics plugins:

useEffect(() => {
    if (shouldRecord) {
        startRecording()
    }
}, [shouldRecord, startRecording])

Demo of loop:

recording-loop-before.mov

After changes:

recording-loop-after.mov

@KaiVandivier KaiVandivier requested review from a team and HendrikThePendric July 18, 2024 21:40
@KaiVandivier KaiVandivier enabled auto-merge (squash) July 26, 2024 16:12
@KaiVandivier KaiVandivier merged commit e3a5fbf into master Jul 26, 2024
@KaiVandivier KaiVandivier deleted the libs-642-stable-references-for-cacheable-sections branch July 26, 2024 16:22
dhis2-bot added a commit that referenced this pull request Jul 26, 2024
## [3.10.6](v3.10.5...v3.10.6) (2024-07-26)

### Bug Fixes

* **cacheable-section:** stable references to avoid loops [LIBS-642] ([#1385](#1385)) ([e3a5fbf](e3a5fbf))
@dhis2-bot
Copy link
Copy Markdown
Contributor

KaiVandivier added a commit that referenced this pull request Nov 25, 2024
…1385)

* fix(cacheable-sections): stable references

* refactor: avoid needing eslint disable

* chore: consistent test names
KaiVandivier pushed a commit that referenced this pull request Nov 25, 2024
* **cacheable-section:** stable references to avoid loops [LIBS-642] ([#1385](#1385)) ([e3a5fbf](e3a5fbf))
dhis2-bot added a commit that referenced this pull request Nov 26, 2024
# [3.11.0-alpha.1](v3.10.4-alpha.1...v3.11.0-alpha.1) (2024-11-26)

### Bug Fixes

* **cacheable-section:** synchronously flush recording state for UI consistency ([04bc604](04bc604))
* add endpoint to text plain matchers ([#1390](#1390)) ([de8fbec](de8fbec))
* expand FetchErrorDetails type ([#1389](#1389)) ([78ad0b3](78ad0b3))
* handle alert returned async by parentAlertsAdd [LIBS-695] ([#1388](#1388)) ([bba9c23](bba9c23))
* **cacheable-section:** stable references to avoid loops [LIBS-642] ([#1385](#1385)) ([31562e9](31562e9))
* update plugin sizing definition ([#1383](#1383)) ([38c09b9](38c09b9))
* **deps:** remove cli-app-scripts peer dep [LIBS-587] ([#1379](#1379)) ([9e22e88](9e22e88))
* **deps:** update cli-app-scripts for package/types race condition ([dee6795](dee6795))

### Features

* fixed dimensions efficiency ([#1386](#1386)) ([b56ad2d](b56ad2d))
* upgrade app-runtime React version to v18 ([#1387](#1387)) ([0e4a3d5](0e4a3d5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants