Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions hooks/test/browser/useState.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('useState', () => {
});

afterEach(() => {
Component.prototype.shouldComponentUpdate = undefined;
teardown(scratch);
});

Expand Down Expand Up @@ -476,4 +477,64 @@ describe('useState', () => {
expect(renders).to.equal(2);
});
});

it('Works when we combine strict equality, signals bail and state settling', () => {
// In signals we bail when we are using no signals/computeds/....
Component.prototype.shouldComponentUpdate = function (
nextProps,
nextState
) {
return false;
};
let setA, setB;

const fooContext = createContext();
const barContext = createContext();

function FooProvider({ children }) {
const [a, _setA] = useState(0);
setA = _setA;
return <fooContext.Provider value={a}>{children}</fooContext.Provider>;
}

function BarProvider({ children }) {
const [b, _setB] = useState(0);
setB = _setB;
return <barContext.Provider value={b}>{children}</barContext.Provider>;
}

function Child() {
const a = useContext(fooContext);
const b = useContext(barContext);
return (
<p>
{a}-{b}
</p>
);
}

function App() {
return (
<FooProvider>
<BarProvider>
<Child />
</BarProvider>
</FooProvider>
);
}

render(<App />, scratch);
expect(scratch.innerHTML).to.equal('<p>0-0</p>');

act(() => {
// We update A first so that we have a top-down render going on
setA(1);
// The update will bail at B, we don't want sCU to run because
// else we risk the state's _nextValue being settled too early
// and thus applying the update too early and bailing on the subsequent
// render due to the values already being applied.
setB(1);
});
expect(scratch.innerHTML).to.equal('<p>1-1</p>');
});
});
4 changes: 2 additions & 2 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ export function diff(
}

if (
newVNode._original == oldVNode._original ||
(!(c._bits & COMPONENT_FORCE) &&
c.shouldComponentUpdate != NULL &&
c.shouldComponentUpdate(
newProps,
c._nextState,
componentContext
) === false) ||
newVNode._original == oldVNode._original
) === false)
) {
// More info about this here: https://gist.github.com/JoviDeCroock/bec5f2ce93544d2e6070ef8e0036e4e8
if (newVNode._original != oldVNode._original) {
Expand Down
Loading