-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Custom _document file example for styled-components throws a TS bug after updating @types/react to ^18.0.0 #36008
Comments
Chiming in because I am experiencing the same error after upgrading. |
This comment was marked as off-topic.
This comment was marked as off-topic.
You can fix it by returning an array as follows:
I would be glad to contribute an example with types for the use of styled with next.js and Typescript. Unfortunately, there are no official docs for that. (Current example with no types)[https://github.com/vercel/next.js/blob/canary/examples/with-styled-components-babel/pages/_document.js] |
One thing should be noted: if you're using
in |
Unfortunately, this doesn't seem to be the case; not for me at least. I'm getting a FOUC even with
unless I have a |
This works but It introduced new warning:
|
While I haven't tried it, I'm guessing that could be fixed with an explicit import {Fragment} from "react";
// ...
return {
...initialProps,
styles: [
<Fragment key="1">
{initialProps.styles}
{sheet.getStyleElement()}
</Fragment>,
],
}; |
@javlund Hi adding an explicit fragment tag & a key fixed that error but it introduced new TS error:
Also getting another TS error in react date picker lib, so I am reverting to old react typings for now. |
The reported issues here are coming from upstream/third-party libraries, and are not related to Next.js. These should be reported on the respective repositories. Some useful links:
I'm closing this for now. If you still think there is a problem with Next.js itself, please provide a reproduction in a new issue so we can look more into it. |
@javlund your suggestion with npx yarn-deduplicate --packages @types/react
yarn Actually React date picker lib has mentioned But with this I think Next.js official TS example with styled-components needs an update. & it seems we need to add this even if we turn on |
I'm not really sure why the array is necessary as the type definition states: export declare type DocumentInitialProps = RenderPageResult & {
styles?: React.ReactElement[] | React.ReactFragment;
}; However, just trying to do a straight fragment without an array doesn't seem to work. |
This PR is looking forward to improve documentation exemples about usage of Next.js with Typescript and Styled-components. I added Typescript types to the original exemple [Example app with styled-components using babel ](https://github.com/vercel/next.js/tree/canary/examples/with-styled-components-babel) ## Feature - [x] Related issues linked using - [x] Documentation added ## Documentation / Examples - [x] Make sure the linting passes by running `yarn lint` fixes #36008
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
I'm not entirely sure if it should be posted here or as an issue in the types/SC repo, so sorry if it shouldn't be here.
After updating @types/react to 18.0.0, I started noticing an error in the _documents.tsx file when using this approach for styled components.. I now get an error which says
Upon further investigation I discovered that in this part:
the overwrite of styles seems to be causing trouble.
styles
are of typestyles?: ReactFragment | ReactElement<any, string | JSXElementConstructor<any>>[] | undefined
instead ofJSX.Element
. If we downgrade types back to "^17.0.43", it doesn't seem to be a problem anymore.Expected Behavior
Types should work correctly if the example made by SC is still relevant.
To Reproduce
You can create a new project with
create next-app --typescript
and add the document from the file I linked above, you should see the error immediately.The text was updated successfully, but these errors were encountered: