vitejs / vite-plugin-react-swc

Speed up your Vite dev server with SWC
MIT License
778 stars 50 forks source link

Generic React components without props #112

Closed flammenmensch closed 1 year ago

flammenmensch commented 1 year ago

Error Unexpected token 'RadioGroup'. Expected jsx identifier when using generics in react components.

The following code produces the error above even though it is a valid tsx:

<RadioGroup<string> ...>
  {renderChildren()}
</RadioGroup>
ArnaudBarre commented 1 year ago

Can you provide a repro? Its working for me in multiple project so probably an issue with an outdated SWC version

flammenmensch commented 1 year ago

Here is the example: https://github.com/flammenmensch/swc-demo It seems that the error occurs only when there are no other props:

<Component<string>>
  ...
</Component>

This code works fine:

<Component<string> value="Hello world">
  ...
</Component>
ArnaudBarre commented 1 year ago

This is a regression in SWC: https://github.com/swc-project/swc/issues/7456 The last working version is 1.3.58 You can pin the version is via the resolutions/overrides: https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides