Skip to content

Ignore props without a restyle function in buildStyle - #359

Open
cpruijsen wants to merge 2 commits into
Shopify:masterfrom
cpruijsen:fix/issue-169-57fe95a4
Open

cpruijsen wants to merge 2 commits into
Shopify:masterfrom
cpruijsen:fix/issue-169-57fe95a4

Conversation

@cpruijsen

Copy link
Copy Markdown

Description

Fixes #169

buildStyle in src/composeRestyleFunctions.ts now skips keys that have no Restyle function, instead of crashing with TypeError: funcsMap[propKey] is not a function. filterRestyleProps already treats unknown component props the same way.

Since 2.1.0, useRestyle sets variant to 'defaults' on every render, so createVariant always calls buildStyle. Two inputs give it keys with no Restyle function:

  • The theme has no textVariants, or the component renders outside a ThemeProvider. 'defaults' does not resolve, and createVariant spreads the string into the keys 0, 1, 2 and so on. A minimal theme with createText hits this.
  • A variant contains a prop that is not a Restyle prop, for example transform.

Two judgement calls:

  • The guard is in buildStyle because that is the crash site and it covers both inputs and all callers. A narrower fix in createVariant is possible if you prefer it.
  • Unknown keys are skipped silently. One comment in the issue asks for a dev-time warning or a descriptive error to catch typos in variants. I can switch to either.

Reviewers' hat-rack 🎩

  • createText renders when the theme has no textVariants.
  • A variant that contains a prop that is not a Restyle prop (for example transform) renders its Restyle props and ignores the other prop.
  • The new tests in createText.test.tsx and createVariant.test.ts fail on master with the reported error.

Screenshots or videos (if needed)

Not applicable. Jest tests cover the change.

Checklist

This branch has not been deployed

No deployments
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.

TypeError: funcsMap[propKey] is not a function when using createText()

1 participant