Skip to content

Primer leading/trailingVisual and Icons cannot be lazy, memo, forwardRef #3430

Description

@mattcosta7

Description

related potentially, but not exactly - #2457

This would not be necessary if we passed rendered elements as props instead of passing components (as the linked PR above suggests)

Primer defines some props that accept function components however they don't accept things like forwardRef components, memoized components or lazy components (at least)

Where does this show up?

Places like this one -

{typeofLeadingVisual==='function' ? <LeadingVisual/> : LeadingVisual}

this should render anything that's component-like, and not just function components, but it only handles function components.

something like this using react-is might be what we want here, with type updates to match

import{isValidElementType}from'react-is'{isValidElementType(LeadingVisual) ? <LeadingVisual/> : LeadingVisual}

When using primer/octicons-react version 19+, these components break because icons are all forwardRef components in that version

Attempting to use v19+ in github/github also trips these failures - https://github.com/github/github/pull/276931

Steps to reproduce

Attempt to pass a memoized, lazy or ref forwarding component to a leadingVisual

Version

latest

Browser

No response

Activity

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

Metadata

Metadata

Labels

bugSomething isn't workingreact

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions