Skip to content

Commit

Permalink
Set the provider value to the new one since in diff its old
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianbote committed Sep 17, 2019
1 parent 1f5dc02 commit 4d339fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/create-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ export function createContext(defaultValue) {
};
this.shouldComponentUpdate = _props => {
if (props.value !== _props.value) {
ctx[context._id].props.value = _props.value;
subs.some(c => {
// Check if still mounted
if (c._parentDom) {
c.context = props.value;
c.context = _props.value;
enqueueRender(c);
}
});
Expand Down
6 changes: 5 additions & 1 deletion test/browser/createContext.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createElement as h, render, Component, createContext } from '../../src/
import { setupScratch, teardown } from '../_util/helpers';
import { Fragment } from '../../src';
import { i as ctxId } from '../../src/create-context';
import options from '../../src/options';

/** @jsx h */

Expand Down Expand Up @@ -352,6 +353,10 @@ describe('createContext', () => {
});

it('should not re-render the consumer if the context doesn\'t change', () => {

// Disable the debounce rendering
options.debounceRendering = f => f();

const { Provider, Consumer } = createContext();
const CONTEXT = { i: 1 };

Expand Down Expand Up @@ -408,7 +413,6 @@ describe('createContext', () => {
);

// Rendered three times, should call 'Consumer' render two times
// Logged these things I think we're dealing with another stale dom issue due to NoUpdate... :/
expect(Inner.prototype.render).to.have.been.calledTwice.and.calledWithMatch({ i: 2 }, {}, { ['__cC' + (ctxId - 1)]: {} });
expect(scratch.innerHTML).to.equal('<div>2</div>');
});
Expand Down

0 comments on commit 4d339fb

Please sign in to comment.