elements icon indicating copy to clipboard operation
elements copied to clipboard

Code updates required for React 18

Open dotslashderek opened this issue 3 years ago • 3 comments

The FC interface in React versions before 18 provided an implicit children field (ReactNode type) that we leverage quite a bit in our code. In 18, this field was removed, so updating will cause breaking changes in our existing code in both elements and elements-core. There are multiple ways to update the existing code to accommodate this change, several of which are outlined here:

https://stackoverflow.com/questions/71788254/react-18-typescript-children-fc

Example of the type errors we receive if updating to 18 without making code changes:

../packages/elements-core/src/components/Docs/Docs.tsx:137:10 - error TS2322: Type '{ children: Element; document: unknown; resolver: ReferenceResolver | undefined; }' is not assignable to type 'IntrinsicAttributes & InlineRefResolverProviderProps'. Property 'children' does not exist on type 'IntrinsicAttributes & InlineRefResolverProviderProps'.

137 <InlineRefResolverProvider document={parsedNode.data} resolver={refResolver}> ~~~~~~~~~~~~~~~~~~~~~~~~~

../packages/elements-core/src/components/Docs/HttpOperation/Body.tsx:42:8 - error TS2322: Type '{ children: false | Element; title: string; id: string; }' is not assignable to type 'IntrinsicAttributes & ISectionTitle'. Property 'children' does not exist on type 'IntrinsicAttributes & ISectionTitle'.

42 <SectionSubtitle title="Body" id="request-body"> ~~~~~~~~~~~~~~~

Lets use this as an opportunity to determine a code update path required for new versions of React as this will also impact other stoplight repos when they attempt to use version 18+ of React.

dotslashderek avatar Jun 09 '22 17:06 dotslashderek

Hey team! Please add your planning poker estimate with ZenHub @Amjcraft @kaylachun @mallachari @mmiask @Nezteb @dotslashderek

mnaumanali94 avatar Jun 14 '22 15:06 mnaumanali94

Document how we did this for other places that we might want to update to react 18

mnaumanali94 avatar Jun 14 '22 15:06 mnaumanali94

Moving this guy back for now. Had quite a few issues with the update. Feel free to ping me if you pick up I did get pretty far into the process and will be continuing to play with it in my free time.

Amjcraft avatar Aug 03 '22 14:08 Amjcraft

Is this something that will see a path forward sometime? It's a bit bizarre to see a repository still referring solely ^16.8 and ^17.

Aeolun avatar Aug 10 '23 00:08 Aeolun