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.
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
playroom/src/utils/componentsToHints.ts
Line 26 in 1b996eb
If I'm understanding this correctly,
components👆 are derived from whatever file location is passed to thePlayroomProps['components']setting. So if acomponentsfile contains even 1 export that isn't a viable component with props, this line breaks e.g. aProxylikechakra-factory.If that
Proxyis one of the many components exported fromPlayroomProps['components']... afunctionwill indeed get passed toparsePropTypesand 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
parsePropTypesis 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 allexportsfromPlayroomProps['components']are definitely component types.Right now, the project I'm maintaining that has this issue has a large
components/indexand 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.