MCPcopy Create free account
hub / github.com/RobPruzan/react-scratch / triggerReRender

Function triggerReRender

src/react/core.ts:1526–1611  ·  view source on GitHub ↗
({
  capturedCurrentlyRenderingRenderNode,
}: {
  capturedCurrentlyRenderingRenderNode: RealElement & {
    parent: null | ReactRenderTreeNode;
  };
})

Source from the content-addressed store, hash-verified

1524 return useMemo(() => fn, deps);
1525};
1526const triggerReRender = ({
1527 capturedCurrentlyRenderingRenderNode,
1528}: {
1529 capturedCurrentlyRenderingRenderNode: RealElement & {
1530 parent: null | ReactRenderTreeNode;
1531 };
1532}) => {
1533 if (!capturedCurrentlyRenderingRenderNode.computedViewTreeNodeId) {
1534 throw new Error(
1535 "Invariant: set state trying to re-render unmounted component"
1536 );
1537 }
1538
1539 if (!currentTreeRef.viewTree || !currentTreeRef.renderTree) {
1540 throw new Error("Invariant error, no view tree or no render tree");
1541 }
1542
1543 const parentNode = findParentViewNode(
1544 capturedCurrentlyRenderingRenderNode.computedViewTreeNodeId
1545 );
1546
1547 if (parentNode.kind === "empty-slot") {
1548 throw new Error("Invariant Error: An empty slot cannot have any children");
1549 }
1550
1551 const clonedParentNode = Utils.deepCloneTree(parentNode);
1552
1553 console.log("\n\nRENDER START----------------------------------------------");
1554
1555 const previousViewTree =
1556 clonedParentNode?.childNodes.find(
1557 (node) =>
1558 node.id === capturedCurrentlyRenderingRenderNode.computedViewTreeNodeId
1559 ) ?? currentTreeRef.viewTree.root;
1560
1561 const reGeneratedViewTree = generateViewTree({
1562 renderNode: capturedCurrentlyRenderingRenderNode,
1563 parentViewNode: parentNode,
1564 });
1565 console.log("RENDER END----------------------------------------------\n\n");
1566
1567 // its a detached node and because of that we set it as the root
1568 const index = parentNode?.childNodes.findIndex(
1569 (node) =>
1570 capturedCurrentlyRenderingRenderNode.internalMetadata.kind ===
1571 "empty-slot" ||
1572 node.kind === "empty-slot" ||
1573 node.metadata.kind === "empty-slot"
1574 ? false
1575 : capturedCurrentlyRenderingRenderNode.internalMetadata.id ===
1576 node.metadata.id // changes this might be dangerous, but no idea why we used the key before
1577 );
1578 // this will always be in the parent nodes children (or is root)
1579 // because we re-rendered at capturedCurrentlyRenderingRenderNode,
1580 // so the previous parent must contain it
1581 // we can now update the view tree by replacing by component
1582 // equality (lets go keys)
1583 if (!parentNode || index === undefined || index === -1) {

Callers 1

useStateFunction · 0.85

Calls 3

findParentViewNodeFunction · 0.85
generateViewTreeFunction · 0.85
updateDomFunction · 0.85

Tested by

no test coverage detected