valotas / preact-context

React new Context API for preact
Other
151 stars 8 forks source link

Adding a child consumer while updating provider value does not render the last consumer child correctly #20

Closed elhesuu closed 6 years ago

elhesuu commented 6 years ago

I'm currently experiencing an issue when multiple consumers are conditionally rendered:

https://jsfiddle.net/jesusvilar/9h28gymb/36/

Notice that in the last consumer, value is not updated.

It seems to me that registration to the provider happens immediately after rendering a consumer. If changing the value of provider is done at the same time as conditionally rendering a consumer, the consumer won't pick the updated value.

Is the emitter not supposed to update the value when it registers?

https://github.com/valotas/preact-context/blob/master/src/context-value-emitter.ts#L20

Also, same jsfiddle using React 16: https://jsfiddle.net/jesusvilar/nLaqb7os/

valotas commented 6 years ago

Hi @elhesuu, this looks like a bug. I will have a look at it asap

valotas commented 6 years ago

Hey @elhesuu, v1.1.2 contains a fix. Have fun.

elhesuu commented 6 years ago

Great stuff, thank you!