Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ignore invalid exported components #140

Merged
merged 12 commits into from Oct 19, 2020
Merged

fix: Ignore invalid exported components #140

merged 12 commits into from Oct 19, 2020

Conversation

fwouts
Copy link
Contributor

@fwouts fwouts commented Mar 27, 2020

Playroom currently expects that every single export in the components module is a valid React component.

For example, export const NotAComponent = 1 would result in Playroom exposing a broken component called <NotAComponent>.

Another issue pointed in #138 is that an exported value of undefined will crash Playroom. This happens in particular when a TypeScript type is explicitly exported in an export declaration statement such as export { Component, SomeType }.

This can all be resolved by filtering out any value that isn't a function. This isn't perfect, as it will still accept non-React functions and classes, but should at least fix a good portion of bugs experienced by people trying out the tool for the first time.

This fixes #138.

@fwouts
Copy link
Contributor Author

fwouts commented Mar 28, 2020

I'm not quite sure what's going on with the broken test, would welcome some help debugging it.

@fwouts
Copy link
Contributor Author

fwouts commented Apr 6, 2020

Woohoo, it's passing! Ready for review 😃

@fwouts
Copy link
Contributor Author

fwouts commented Apr 21, 2020

@michaeltaranto @markdalgleish What's the current status of the Playroom project? Has it been put on hold because of COVID-19?

@michaeltaranto
Copy link
Contributor

michaeltaranto commented Apr 21, 2020

Sorry mate, the world did flip upside down, but that is not why this PR has not been merged reviewed — we have just been busy elsewhere in our ecosystem. Looking at a few tweaks to playroom at the moment, so will check this out soon.

Thanks for taking the time.

@michaeltaranto michaeltaranto requested a review from a team as a code owner April 22, 2020 23:34
@fwouts
Copy link
Contributor Author

fwouts commented May 24, 2020

Tests keep failing, I'm not sure what's going on. The Cypress code uses patterns that tend to result in flakiness (e.g. sleeps for 200ms and 1000ms) and master itself is failing, so I'll assume that's the reason :)

@fwouts
Copy link
Contributor Author

fwouts commented Jul 10, 2020

Glad to see Cypress tests now seem more stable!

@michaeltaranto FYI this is now up-to-date with master :)

@fwouts
Copy link
Contributor Author

fwouts commented Jul 21, 2020

Friendly ping 🏓

@fwouts
Copy link
Contributor Author

fwouts commented Sep 8, 2020

Hello 👋

@michaeltaranto
Copy link
Contributor

Apologies for taking so long to come back to this. This is a tricky one, as filtering of consumers exports is not really something that feels right to be maintained by Playroom itself.

In practice we have found that pointing Playroom at a file that exports only what you want to be available is becoming more the encouraged approach.

That feels like a less opinionated path forward to me.

@fwouts
Copy link
Contributor Author

fwouts commented Sep 14, 2020

No worries, I can see the reasoning. How about just filtering out undefined at least to reduce the confusion when it crashes?

@michaeltaranto
Copy link
Contributor

Yeah maybe that makes more sense as a defensive approach. Might be worth memoizing that in renderPlayroom function so that the filtering is only re-run when/if components changes.

Thoughts?

@fwouts
Copy link
Contributor Author

fwouts commented Oct 19, 2020

Sorry for the delay, I've updated the PR. Not sure it's worth the additional code for memoizing but it's easy to add if you'd like :)

@markdalgleish markdalgleish merged commit 0c69e1c into seek-oss:master Oct 19, 2020
@markdalgleish
Copy link
Member

Thanks for the PR!

@fwouts fwouts deleted the 138-typescript-crash branch October 19, 2020 11:21
@fwouts
Copy link
Contributor Author

fwouts commented Oct 19, 2020

And thanks for the prompt release! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exporting a TypeScript interface crashes Playroom
3 participants