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 "Invalid hook call" warning #3769

Merged
merged 4 commits into from
Jun 30, 2022

Conversation

hippotastic
Copy link
Contributor

Changes

  • In our Preact integration's check function, we attempt to render JSX components through Preact. When attempting this on a React component that uses hooks, React outputs the following warning message:

    Warning: Invalid hook call. Hooks can only be called inside of the body of a function component.
    This could happen for one of the following reasons:
    1. You might have mismatching versions of React and the renderer (such as React DOM)
    2. You might be breaking the Rules of Hooks
    3. You might have more than one copy of React in the same app
    See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
    
  • This PR fixes this behavior by filtering this known message from console.error output while any check function call is running.

Testing

  • Ran all tests locally.
  • Built Astro Docs using the updated integration, which removed the unwanted warnings successfully both during build and dev.

Docs

  • Not a visible change, just a bugfix.

@changeset-bot
Copy link

changeset-bot bot commented Jun 29, 2022

🦋 Changeset detected

Latest commit: be0a616

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

This PR includes changesets to release 2 packages
Name Type
@astrojs/preact Patch
@e2e/preact-component Patch

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

@github-actions github-actions bot added pkg: preact Related to Preact (scope) pkg: integration Related to any renderer integration (scope) labels Jun 29, 2022
@hippotastic hippotastic merged commit b934ab5 into withastro:main Jun 30, 2022
@hippotastic hippotastic deleted the fix/preact-invalid-hook-call branch June 30, 2022 12:11
@astrobot-houston astrobot-houston mentioned this pull request Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: integration Related to any renderer integration (scope) pkg: preact Related to Preact (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants