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 auto-id build for backwards compatibility with React <18 #961

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

Conversation

emmenko
Copy link

@emmenko emmenko commented Aug 28, 2022

Summary

Fixes #921

TL;DR: the bundle of @reach/auto-id contains an import of useId from react. For versions of React <18 this import does not exist, causing an error when this package is used.

image

This can also be seen in the Storybook playground build output (although Storybook shows a warning)

image

To fix that, I suggest to remove that code and change the implementation once React >=18 is supported.

I also fixed another import issue shown by Storybook

image


Thank you for contributing to Reach UI! Please fill in this template before submitting your PR to help us process your request more quickly.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code (Compile and run).
  • Add or edit tests to reflect the change (Run with yarn test).
  • Add or edit Storybook examples to reflect the change (Run with yarn start).
  • Ensure formatting is consistent with the project's Prettier configuration.
  • Add documentation to support any new features.

This pull request:

  • Creates a new package
  • Fixes a bug in an existing package
  • Adds additional features/functionality to an existing package
  • Updates documentation or example code
  • Other

If creating a new package:

  • Make sure the new package directory contains each of the following, and that their structure/formatting mirrors other related examples in the project:
    • examples directory
    • src directory with an index.tsx entry file
    • At least one example file per feature introduced by the new package
    • Base styles in a style.css file (if needed by the new package)

Comment on lines +15 to +16
# storybook
/playground/storybook-static
Copy link
Author

Choose a reason for hiding this comment

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

Artifact of building Storybook locally.

Comment on lines -90 to -97
// TODO: Remove error flag when updating internal deps to React 18. None of
// our tricks will play well with concurrent rendering anyway.
// @ts-expect-error
if (typeof React.useId === "function") {
// @ts-expect-error
let id = React.useId(providedId);
return providedId != null ? providedId : id;
}
Copy link
Author

Choose a reason for hiding this comment

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

This is what is causing the problem. I suggest to simply remove this once only React >=18 is supported.

Copy link

Choose a reason for hiding this comment

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

Is there no way to rewrite this to keep your build process from showing a warning? I think that would be preferable.

@@ -1,5 +1,5 @@
import * as React from "react";
import WindowSize from "@reach/window-size";
import { WindowSize } from "@reach/window-size";
Copy link
Author

Choose a reason for hiding this comment

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

The import was wrong

@codesandbox-ci
Copy link

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 a8aed9e:

Sandbox Source
reach-ui-template Configuration

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.

0.17.0 does not work with React 17
2 participants