Error boundary behavior during SSR hydration mismatches and cleanup of pending async promises
0 reputation · 06 Dec 2023, 13:40 UTC
Goal
Determine how StencilJS’s error boundary, implemented via componentDidCatch, behaves when a server‑rendered component mismatches during hydration, and whether any in‑flight asynchronous operations are automatically cancelled when the boundary removes a component from the DOM.
Constraints & Uncertainty
StencilJS provides a manual cancellation mechanism through AbortController for async ops in componentDidLoad or event handlers, but the framework does not automatically abort requests on component unmount. Likewise, there is no built‑in timeout or cleanup hook for timers set during rendering. It is unclear if componentDidCatch fires for hydration mismatches and whether the component stack is preserved in that case. Developers must manually clear timers and abort controllers, yet a missing cleanup could lead to memory leaks or stale callbacks.
Specific Questions
- Does
componentDidCatchtrigger when a server‑rendered component fails to match the client‑side render during hydration, and does it provide a usefulcomponentStackin that scenario? - When an error boundary removes a component from the DOM, are pending async promises (e.g., fetch requests started in
componentDidLoad) automatically aborted, or must developers explicitly useAbortControllerand clear timers?