Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

fix(renderComponent): do not throw if context is missing #1837

Merged
merged 5 commits into from
Aug 21, 2019

Conversation

layershifter
Copy link
Member

Fixes #1834.

}, emptyTheme)
return acc
},
{ ...emptyTheme },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clone is required as it will modify the source object. I have two options:

  • leave a comment
  • use Object.freeze on emptyTheme

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave a comment :)

@codecov
Copy link

codecov bot commented Aug 21, 2019

Codecov Report

Merging #1837 into master will decrease coverage by <.01%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1837      +/-   ##
==========================================
- Coverage   69.49%   69.49%   -0.01%     
==========================================
  Files         875      875              
  Lines        7603     7602       -1     
  Branches     2243     2241       -2     
==========================================
- Hits         5284     5283       -1     
  Misses       2311     2311              
  Partials        8        8
Impacted Files Coverage Δ
packages/react/src/lib/mergeThemes.ts 100% <100%> (ø) ⬆️
packages/react/src/lib/renderComponent.tsx 84.74% <75%> (-0.51%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 57f1c1c...508fd04. Read the comment docs.

@@ -203,7 +195,7 @@ const renderComponent = <P extends {}>(
displayName,
props: stateAndProps,
variables: resolvedVariables,
theme: context.theme,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context can be undefined if there are no wrapping Provider and it will throw an error

@@ -142,7 +142,7 @@ const resolveStyles = (

const renderComponent = <P extends {}>(
config: RenderConfig<P>,
context: ProviderContextPrepared,
context?: ProviderContextPrepared,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I marked context as optional to emphasize that it can be undefined

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that this would fix the problem of not throwing when Provider is not defined, but we are still not telling the user, why the Button is not rendered as expected, if there is no Provider :\ It seems like we are silencing the error, instead of explaining it...

Copy link
Member Author

@layershifter layershifter Aug 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we are telling:
image

And this error will still exist.


But then happens:
image

And I want to fix it, because it causes the app crash in the wrong place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I missed that, thanks for the clarification

@layershifter layershifter marked this pull request as ready for review August 21, 2019 12:09
@lucivpav lucivpav changed the title fix(renderComponent): do not throw if context if missing fix(renderComponent): do not throw if context is missing Aug 21, 2019
Co-Authored-By: Pavel Lučivňák <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🧰 fix Introduces fix for broken behavior. 🚀 ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

renderComponent: usage without Provider throws an unclear error
3 participants