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

Mitigate warnings when using QRCodeSVG in server components #352

Merged
merged 3 commits into from
Jul 8, 2024

Conversation

kachkaev
Copy link
Contributor

@kachkaev kachkaev commented Jul 8, 2024

Closes #347

Before this PR, react hooks were imported as named ESM exports. This could generate bundler warnings in frameworks like Next.js:

 ⚠ ./node_modules/.pnpm/qrcode.react@3.1.0_react@18.3.1/node_modules/qrcode.react/lib/esm/index.js
Attempted import error: 'useRef' is not exported from 'react' (imported as 'useRef').

This PR replaces named imports with properties of the default import. This provides a sufficient workaround for now.

Going forward, we will need to split the library into separate files so that QRCodeSVG could be imported on its own. This will be needed when default react export is removed for tree-shaking. As of React v16...v19, both of these imports are equivalent:

import * as React from 'react';
import React from 'react'; // might not work in React v20+

(see v18 typings & v19 typings from DefinitelyTyped/DefinitelyTyped#69022)

Some extra context:

I guess it’s a patch change: v3.1.0 → v3.1.1.

kachkaev added 3 commits July 8, 2024 21:40
@kachkaev kachkaev changed the title Allow QRCodeSVG to be used in a server component Mitigate warnings when using QRCodeSVG in React server components Jul 8, 2024
@@ -66,5 +66,6 @@
"ts-jest": "^29.1.0",
"tsup": "^8.0.2",
"typescript": "^5.0.4"
}
},
"packageManager": "yarn@1.22.22"
Copy link
Contributor Author

@kachkaev kachkaev Jul 8, 2024

Choose a reason for hiding this comment

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

Side change: this helps Node’s corepack use the right version of yarn. Otherwise, yarn install may pick v4 and mess up the diff.

Copy link
Owner

Choose a reason for hiding this comment

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

This should be done independently but that's ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I agree that this change is unrelated, so should have been in another PR. It was one of those borderline sidecar changes that could be tolerable, so I thought I'd sneak it in 😅

@kachkaev kachkaev changed the title Mitigate warnings when using QRCodeSVG in React server components Mitigate warnings when using QRCodeSVG in server components Jul 8, 2024
@zpao zpao modified the milestones: 4.0.0, 3.2.0 Jul 8, 2024
@@ -66,5 +66,6 @@
"ts-jest": "^29.1.0",
"tsup": "^8.0.2",
"typescript": "^5.0.4"
}
},
"packageManager": "yarn@1.22.22"
Copy link
Owner

Choose a reason for hiding this comment

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

This should be done independently but that's ok.

@zpao
Copy link
Owner

zpao commented Jul 8, 2024

Thanks for finding the minimal change to get this working! I'll definitely get this into 4.0 (soon - might wait for React 19 just to update peerdeps confidently). TBD if I backport into a v3.y.z release. It should be safe like you said, just not sure I care enough to get this an other technically safe things into another v3.

@zpao zpao merged commit 9c269e7 into zpao:trunk Jul 8, 2024
10 checks passed
@kachkaev kachkaev deleted the support-react-server-components branch July 8, 2024 22:46
@kachkaev
Copy link
Contributor Author

kachkaev commented Jul 8, 2024

Waiting for v4 / React v19 makes sense – the warning is not critical. You probably know this already, but they are delaying 19.0.0 because of one issue with Suspense (tweet | details). Not sure what the new ETA is because of that.

If you want to cut v4 beta / rc, happy to give it a spin and share feedback. A backport would be great too, but it’s up to your desire and availability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for server components
2 participants