Preserve shared Link script while hooks remain mounted - #403
Conversation
|
Claude Opus 4.8's review: What it does. useScript (the forked react-script-hook) cached one <script> per src and, on unmount-while-loading, removed it from the DOM and cache — so when several usePlaidLink hooks shared a still-loading script and any one unmounted, the Findings: nothing survived verification. I traced the paths that usually break this kind of refcount and each is sound:
One pre-existing behavior worth being aware of (not introduced here, not blocking): handleError never sets status.loading = false, so an errored-but-still-"loading" script is removed from DOM/cache when its last subscriber unmounts. That's Clean, minimal, correctly-scoped fix with real regression coverage — no changes requested. |
Concurrent
usePlaidLinkinstances share one Link script, but unmounting any instance removed that script while it was still loading and stranded the remaining hooks. This tracks active script subscribers so cleanup occurs only after the final consumer unmounts, with regression coverage for both paths.Closes #268.