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

Add tests for '@reach/utils' and compatibility check with react 18 #960

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from

Conversation

dartess
Copy link
Contributor

@dartess dartess commented Aug 25, 2022

Hi.

I covered all the hooks with tests, except for useIsomorphicLayoutEffect (I have no idea what and how to honestly test there). I don’t see the point in covering individual helpers within this task with tests, mostly they are too simple and/or do not rely to React.

In some hooks, I found problems that I fixed:

  • two bugs in useFocusChange that commented below;
  • insufficient typing in useLazyRef - unnecessarily used any;
  • useUpdateEffect - the cleanup return from the effect was missed, the effects were not cleaned.

I also checked the work of all tests in StrictMode (including react@18). One of the hooks required a rewrite - this is useUpdateEffect. Now it works as intended.

@dartess dartess marked this pull request as draft August 25, 2022 13:26
@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 25, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9af9a61:

Sandbox Source
reach-ui-template Configuration

);
lastActiveElement.current = ownerDocument.activeElement;
if (
when === "focus" &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If do not check it and try use this hook with blur, handleChange will never be called, because ownerDocument.activeElement will be always ownerDocument.body.

}

ownerDocument.addEventListener(when, onChange, true);

return () => {
ownerDocument.removeEventListener(when, onChange);
ownerDocument.removeEventListener(when, onChange, true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removing the handler didn't work before.
demo: https://codepen.io/dartess/pen/rNdgWEj

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.

None yet

1 participant