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) - handle hooks that throw during cleanup #3345

Merged
merged 3 commits into from
Nov 29, 2021

Conversation

JoviDeCroock
Copy link
Member

@JoviDeCroock JoviDeCroock commented Nov 26, 2021

When a hook throws an error during cleanup we want to run all the other cleanups so we can avoid memory leaks and end in a consistent UI.

For this we'll need to always clear the hook._cleanup function so that we don't call it twice. During unmount we want to ensure we run through all hooks and even if we error we defer that to only bubble up the latest error.

fixes #3329

@coveralls
Copy link

coveralls commented Nov 26, 2021

Coverage Status

Coverage increased (+0.001%) to 99.625% when pulling 51d3402 on handle-hook-cleanup-errors into e0e1704 on master.

@github-actions
Copy link

github-actions bot commented Nov 26, 2021

Size Change: +47 B (0%)

Total Size: 42.1 kB

Filename Size Change
hooks/dist/hooks.js 1.14 kB +14 B (1%)
hooks/dist/hooks.module.js 1.16 kB +14 B (1%)
hooks/dist/hooks.umd.js 1.22 kB +19 B (1%)
ℹ️ View Unchanged
Filename Size Change
compat/dist/compat.js 3.44 kB 0 B
compat/dist/compat.module.js 3.42 kB 0 B
compat/dist/compat.umd.js 3.49 kB 0 B
debug/dist/debug.js 2.99 kB 0 B
debug/dist/debug.module.js 2.98 kB 0 B
debug/dist/debug.umd.js 3.07 kB 0 B
devtools/dist/devtools.js 231 B 0 B
devtools/dist/devtools.module.js 240 B 0 B
devtools/dist/devtools.umd.js 307 B 0 B
dist/preact.js 3.97 kB 0 B
dist/preact.min.js 4 kB 0 B
dist/preact.module.js 3.99 kB 0 B
dist/preact.umd.js 4.03 kB 0 B
jsx-runtime/dist/jsxRuntime.js 317 B 0 B
jsx-runtime/dist/jsxRuntime.module.js 327 B 0 B
jsx-runtime/dist/jsxRuntime.umd.js 395 B 0 B
test-utils/dist/testUtils.js 437 B 0 B
test-utils/dist/testUtils.module.js 439 B 0 B
test-utils/dist/testUtils.umd.js 515 B 0 B

compressed-size-action

Copy link
Member

@developit developit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with silly nit

hooks/src/index.js Outdated Show resolved Hide resolved
Co-authored-by: Jason Miller <developit@users.noreply.github.com>
@JoviDeCroock JoviDeCroock merged commit bcc8567 into master Nov 29, 2021
@JoviDeCroock JoviDeCroock deleted the handle-hook-cleanup-errors branch November 29, 2021 15:51
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.

Component unmount fails when exception is thrown from effect cleanup function.
3 participants