From 846a3449f4cdd7e9e4558493fc3c4a3e450fb9b8 Mon Sep 17 00:00:00 2001 From: Ryan Dang Date: Sat, 27 Jul 2019 15:46:59 -0400 Subject: [PATCH] npm package now sends initial state at the very beginning --- package/linkFiber.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/package/linkFiber.js b/package/linkFiber.js index 29ddab9cb..5be9e0ed8 100644 --- a/package/linkFiber.js +++ b/package/linkFiber.js @@ -4,7 +4,6 @@ const Tree = require('./tree'); module.exports = (snap, mode) => { let fiberRoot = null; - let first = true; function sendSnapshot() { // don't send messages while jumping @@ -25,11 +24,6 @@ module.exports = (snap, mode) => { function newSetState(state, callback = () => { }) { // continue normal setState functionality, except add sending message middleware - if (first) { - updateSnapShotTree(); - sendSnapshot(); - first = false; - } oldSetState(state, () => { updateSnapShotTree(); sendSnapshot(); @@ -47,8 +41,11 @@ module.exports = (snap, mode) => { const { sibling, stateNode, child } = currentFiber; let nextTree = tree; + // check if stateful component if (stateNode && stateNode.state) { + // add component to tree nextTree = tree.appendChild(stateNode); + // change setState functionality changeSetState(stateNode); } @@ -68,5 +65,6 @@ module.exports = (snap, mode) => { const { _reactRootContainer: { _internalRoot } } = container; fiberRoot = _internalRoot; updateSnapShotTree(); + sendSnapshot(); }; };