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

Run tests outside of React act environment #2894

Merged
merged 3 commits into from
Oct 1, 2023
Merged

Run tests outside of React act environment #2894

merged 3 commits into from
Oct 1, 2023

Conversation

diegohaz
Copy link
Member

@diegohaz diegohaz commented Oct 1, 2023

This PR removes the need for calling React's act when performing asynchronous tasks using @ariakit/test. More details on reactwg/react-18#102 and WordPress/gutenberg#52133 (comment)

Some breaking changes have been introduced to the @ariakit/test package. Refer to the changeset files for more details.

@vercel
Copy link

vercel bot commented Oct 1, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
ariakit ✅ Ready (Inspect) Visit Preview Oct 1, 2023 8:57am
1 Ignored Deployment
Name Status Preview Updated (UTC)
reakit ⬜️ Ignored (Inspect) Visit Preview Oct 1, 2023 8:57am

@changeset-bot
Copy link

changeset-bot bot commented Oct 1, 2023

🦋 Changeset detected

Latest commit: 29b8244

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@ariakit/react-core Patch
@ariakit/react Patch
@ariakit/test Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@diegohaz diegohaz changed the title Update @ariakit/test to run functions outside of React act environment Run tests outside of React act environment Oct 1, 2023
@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 1, 2023

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 29b8244:

Sandbox Source
Ariakit Configuration

@diegohaz diegohaz merged commit ec8d74a into main Oct 1, 2023
14 checks passed
@diegohaz diegohaz deleted the test-without-act branch October 1, 2023 09:05
This was referenced Oct 1, 2023
diegohaz pushed a commit that referenced this pull request Oct 8, 2023
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @ariakit/test@0.3.0

### Minor Changes

- [`#2894`](#2894) All
`@ariakit/test` functions now disable `global.IS_REACT_ACT_ENVIRONMENT`
before running and restore its value at the end.

- [`#2894`](#2894) Replaced the
synchronous `fireEvent` functions by asynchronous `dispatch` functions.

- [`#2894`](#2894) The `act`
export has been removed.

- [`#2894`](#2894) Exported user
event functions that were previously synchronous are now asyncrhonous.

- [`#2899`](#2899) The `screen`
module and its queries (`getBy*`, `queryBy*`, etc.) have been removed in
favor of the `query` module.

- [`#2899`](#2899) The `within`
module has been removed.

- [`#2900`](#2900) The `render`
function has been moved to the `@ariakit/test/react` path. It's now
asynchronous. The root `@ariakit/test` package does not depend on React
or React Testing Library anymore.

### Patch Changes

- [`#2892`](#2892) Updated
function argument types to support `null` instead of `Element`, but
added a runtime error in case `null` is passed.

- [`#2892`](#2892) Added a new
`query` module that exports a `query`/`q` object with functions to query
the DOM.

-   Updated dependencies: `@ariakit/core@0.3.3`.

## @ariakit/core@0.3.3

### Patch Changes

- [`#2909`](#2909) Fixed
[Disclosure](https://ariakit.org/components/disclosure) and related
components not waiting for the exit animation to complete before hiding
the content element.

-   Improved JSDocs.

## @ariakit/react@0.3.4

### Patch Changes

- [`#2894`](#2894) Fixed
[Command](https://ariakit.org/components/command) and related components
not preventing the default behavior on <kbd>Space</kbd> keyup on
non-native button elements.

- [`#2896`](#2896) Controlled
store updates are no longer flushed synchronously.

Previously, we were wrapping _all_ controlled store updates with
[`ReactDOM.flushSync`](https://react.dev/reference/react-dom/flushSync).
This approach proved to be quite fragile and led to a few problems. Now,
we only apply this to specific updates that require synchronous
flushing.

This change shouldn't impact your application, unless you're already
facing problems, which could be fixed by this. If you find any issues
stemming from this change, please let us know. Regardless, you can
always opt into the previous behavior by wrapping your own updates in
`flushSync` when needed:

    ```js
    const [open, setOpen] = useState(false);

    useDialogStore({
      open,
      setOpen(open) {
        ReactDOM.flushSync(() => setOpen(open));
      },
    });
    ```

- [`#2909`](#2909) Fixed
[Disclosure](https://ariakit.org/components/disclosure) and related
components not waiting for the exit animation to complete before hiding
the content element.

- [`#2909`](#2909) The
[Dialog](https://ariakit.org/components/dialog) and related components
can now receive controlled
[`open`](https://ariakit.org/reference/dialog#open) and
[`onClose`](https://ariakit.org/reference/dialog#onclose) props,
allowing them to be used without a store:

    ```jsx
    const [open, setOpen] = useState(false);

    <Dialog
      open={open}
      onClose={() => setOpen(false)}
    >
    ```

- [`#2922`](#2922) Added
[`unmountOnHide`](https://ariakit.org/reference/disclosure-content#unmountonhide)
prop to
[`DisclosureContent`](https://ariakit.org/reference/disclosure-content),
[`Dialog`](https://ariakit.org/reference/dialog) and related components.

Conditionally rendering the
[`Dialog`](https://ariakit.org/reference/dialog) and related components
will continue to work as before:

    ```jsx
    open && <Dialog>
    ```

Now, you can do the same thing using the
[`unmountOnHide`](https://ariakit.org/reference/dialog#unmountonhide)
prop:

    ```jsx
    <Dialog unmountOnHide>
    ```

-   Improved JSDocs.

-   Updated dependencies: `@ariakit/react-core@0.3.4`.

## @ariakit/react-core@0.3.4

### Patch Changes

- [`#2894`](#2894) Fixed
[Command](https://ariakit.org/components/command) and related components
not preventing the default behavior on <kbd>Space</kbd> keyup on
non-native button elements.

- [`#2896`](#2896) Controlled
store updates are no longer flushed synchronously.

Previously, we were wrapping _all_ controlled store updates with
[`ReactDOM.flushSync`](https://react.dev/reference/react-dom/flushSync).
This approach proved to be quite fragile and led to a few problems. Now,
we only apply this to specific updates that require synchronous
flushing.

This change shouldn't impact your application, unless you're already
facing problems, which could be fixed by this. If you find any issues
stemming from this change, please let us know. Regardless, you can
always opt into the previous behavior by wrapping your own updates in
`flushSync` when needed:

    ```js
    const [open, setOpen] = useState(false);

    useDialogStore({
      open,
      setOpen(open) {
        ReactDOM.flushSync(() => setOpen(open));
      },
    });
    ```

- [`#2897`](#2897) Fixed
`CompositeRenderer` missing its `items` state when used in a component
with a `mounted` state.

- [`#2909`](#2909) Fixed
[Disclosure](https://ariakit.org/components/disclosure) and related
components not waiting for the exit animation to complete before hiding
the content element.

- [`#2909`](#2909) The
[Dialog](https://ariakit.org/components/dialog) and related components
can now receive controlled
[`open`](https://ariakit.org/reference/dialog#open) and
[`onClose`](https://ariakit.org/reference/dialog#onclose) props,
allowing them to be used without a store:

    ```jsx
    const [open, setOpen] = useState(false);

    <Dialog
      open={open}
      onClose={() => setOpen(false)}
    >
    ```

- [`#2922`](#2922) Added
[`unmountOnHide`](https://ariakit.org/reference/disclosure-content#unmountonhide)
prop to
[`DisclosureContent`](https://ariakit.org/reference/disclosure-content),
[`Dialog`](https://ariakit.org/reference/dialog) and related components.

Conditionally rendering the
[`Dialog`](https://ariakit.org/reference/dialog) and related components
will continue to work as before:

    ```jsx
    open && <Dialog>
    ```

Now, you can do the same thing using the
[`unmountOnHide`](https://ariakit.org/reference/dialog#unmountonhide)
prop:

    ```jsx
    <Dialog unmountOnHide>
    ```

-   Improved JSDocs.

-   Updated dependencies: `@ariakit/core@0.3.3`.

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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