Skip to content

componentsToHints breaks if PlayRoomProps.components file contains something other than a component #259

Description

@w0ofy

Request

Could a condition/filter be added to guarantee that an object is passed to parsePropTypes? Actually, not 100% sure of the ideal approach... would need to dig deeper, but here in lies the problem 👇

Why

const parsedPropTypes = parsePropTypes(components[componentName]);

If I'm understanding this correctly, components 👆 are derived from whatever file location is passed to the PlayroomProps['components'] setting. So if a components file contains even 1 export that isn't a viable component with props, this line breaks e.g. a Proxy like chakra-factory.

If that Proxy is one of the many components exported from PlayroomProps['components']... a function will indeed get passed to parsePropTypes and that function will fail because it is expecting an object as an argument and doesn't have a fail-safe.

The thing is, the argument for parsePropTypes is strictly typed to require an object, so it sorta makes sense to me to ensure the argument passed into it is conditioned for passing the acceptable type. Rather than assuming all exports from PlayroomProps['components'] are definitely component types.

Right now, the project I'm maintaining that has this issue has a large components/index and it would be a pain the neck if we had to automate creating a second file—less a few exports—just to ensure playroom doesn't break.

P.S.

If anything is unclear, I'd be happy to elaborate. I can also raise a PR if that makes things easier.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions