You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected Behaviour:
element1 should have been appended to the container1 and element2 should have been appended to the container2.
Current Behaviour:
Only element2 is being appended to container2.
Reason:
The second render call is executed before workLoop is executed for the first time as a result wipRoot and nextUnitOfWork change before the first render call gets the chance to render element1, container1.
Possible Fix:
Instead of assigning wipRoot in the render function, we maintain a queue of wipRoot.
In workLoop we check if there is no nextUnitOfwork and wipQueue is not empty then we pop the first element assign it to wipRoot and set the nextUnitOfWork.
let wipQueue = [];
function render(element, container) {
let tWipRoot;
tWipRoot = {
dom: container,
props: {
children: [element],
},
alternate: currentRoot,
};
deletions = [];
wipQueue.push(tWipRoot);
}
function workLoop(deadline) {
let shouldYield = false;
if (!nextUnitOfWork && wipQueue) {
wipRoot = wipQueue.shift();
nextUnitOfWork = wipRoot;
}
while (nextUnitOfWork && !shouldYield) {
nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
shouldYield = deadline.timeRemaining() < 1;
}
if (!nextUnitOfWork && wipRoot) {
commitRoot();
}
Although this solution works, we also have to maintain another list of currentRoot for hooks to work.
Also, I am new to JS and front-end in general. So there might be a better solution, Just wanted to share my thoughts.
The text was updated successfully, but these errors were encountered:
Expected Behaviour:
element1 should have been appended to the container1 and element2 should have been appended to the container2.
Current Behaviour:
Only element2 is being appended to container2.
Reason:
The second render call is executed before workLoop is executed for the first time as a result wipRoot and nextUnitOfWork change before the first render call gets the chance to render element1, container1.
Possible Fix:
Although this solution works, we also have to maintain another list of currentRoot for hooks to work.
Also, I am new to JS and front-end in general. So there might be a better solution, Just wanted to share my thoughts.
The text was updated successfully, but these errors were encountered: