Skip to content

Commit 6cdd844

Browse files
authored
fix: dirty status on repo initial loading (#326)
1 parent 51fc227 commit 6cdd844

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

ui/src/components/nodes/Code.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,20 @@ export const ResultBlock = memo<any>(function ResultBlock({ id, layout }) {
8080
const result = useStore(store, (state) => state.pods[id]?.result);
8181
const error = useStore(store, (state) => state.pods[id]?.error);
8282
const stdout = useStore(store, (state) => state.pods[id]?.stdout);
83-
const running = useStore(store, (state) => state.pods[id]?.running);
83+
const running = useStore(store, (state) => state.pods[id]?.running || false);
8484
const autoLayoutROOT = useStore(store, (state) => state.autoLayoutROOT);
85+
const autoRunLayout = useStore(store, (state) => state.autoRunLayout);
86+
87+
const prevRunning = useRef(false);
8588
useEffect(() => {
86-
autoLayoutROOT();
89+
if (autoRunLayout) {
90+
if (prevRunning.current != running) {
91+
autoLayoutROOT();
92+
prevRunning.current = running;
93+
}
94+
}
8795
}, [running]);
96+
8897
const lastExecutedAt = useStore(
8998
store,
9099
(state) => state.pods[id]?.lastExecutedAt
@@ -474,9 +483,17 @@ export const CodeNode = memo<NodeProps>(function ({
474483

475484
const nodesMap = useStore(store, (state) => state.ydoc.getMap<Node>("pods"));
476485
const autoLayoutROOT = useStore(store, (state) => state.autoLayoutROOT);
486+
const autoRunLayout = useStore(store, (state) => state.autoRunLayout);
487+
488+
const prevLayout = useRef(layout);
477489
useEffect(() => {
478-
// Run auto-layout when the output box layout changes.
479-
autoLayoutROOT();
490+
if (autoRunLayout) {
491+
// Run auto-layout when the output box layout changes.
492+
if (prevLayout.current != layout) {
493+
autoLayoutROOT();
494+
prevLayout.current = layout;
495+
}
496+
}
480497
}, [layout]);
481498

482499
const onResizeStop = useCallback(
@@ -503,7 +520,9 @@ export const CodeNode = memo<NodeProps>(function ({
503520
true
504521
);
505522
updateView();
506-
autoLayoutROOT();
523+
if (autoRunLayout) {
524+
autoLayoutROOT();
525+
}
507526
}
508527
},
509528
[id, nodesMap, setPodGeo, updateView, autoLayoutROOT]

ui/src/components/nodes/Rich.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,9 @@ const MyStyledWrapper = styled("div")(
473473
// FIXME re-rendering performance
474474
const MyEditor = ({
475475
placeholder = "Start typing...",
476-
initialContent,
477476
id,
478477
}: {
479478
placeholder?: string;
480-
initialContent?: string;
481479
id: string;
482480
}) => {
483481
// FIXME this is re-rendered all the time.
@@ -540,6 +538,8 @@ const MyEditor = ({
540538
stringHandler: htmlToProsemirrorNode,
541539
});
542540

541+
let index_onChange = 0;
542+
543543
return (
544544
<Box
545545
className="remirror-theme"
@@ -567,6 +567,16 @@ const MyEditor = ({
567567
setState(nextState);
568568
// TODO sync with DB and yjs
569569
if (parameter.tr?.docChanged) {
570+
index_onChange += 1;
571+
if (index_onChange == 1) {
572+
if (
573+
JSON.stringify(pod.content) ===
574+
JSON.stringify(nextState.doc.toJSON())
575+
) {
576+
// This is the first onChange trigger, and the content is the same. Skip it.
577+
return;
578+
}
579+
}
570580
setPodContent({ id, content: nextState.doc.toJSON() });
571581
}
572582
}}
@@ -702,6 +712,7 @@ export const RichNode = memo<Props>(function ({
702712

703713
const [showToolbar, setShowToolbar] = useState(false);
704714
const autoLayoutROOT = useStore(store, (state) => state.autoLayoutROOT);
715+
const autoRunLayout = useStore(store, (state) => state.autoRunLayout);
705716

706717
const onResizeStop = useCallback(
707718
(e, data) => {
@@ -727,7 +738,9 @@ export const RichNode = memo<Props>(function ({
727738
true
728739
);
729740
updateView();
730-
autoLayoutROOT();
741+
if (autoRunLayout) {
742+
autoLayoutROOT();
743+
}
731744
}
732745
},
733746
[id, nodesMap, setPodGeo, updateView, autoLayoutROOT]

ui/src/lib/store/canvasSlice.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,17 @@ export const createCanvasSlice: StateCreator<MyState, [], [], CanvasSlice> = (
790790
// be filed for CodeNode at the beginning or anytime the node height
791791
// is changed due to content height changes.
792792
const node = nextNodes.find((n) => n.id === change.id);
793-
if (!node) throw new Error("Node not found");
793+
const prevNode = nodes.find((n) => n.id === change.id);
794+
if (!node || !prevNode) throw new Error("Node not found");
795+
// At the beginning, a dimension change is fired for all pods for no
796+
// good reason. This will cause all pods being marked dirty and get
797+
// uploaded. Filter out that situation here.
798+
if (
799+
node.width === prevNode.width &&
800+
node.height === prevNode.height
801+
) {
802+
break;
803+
}
794804

795805
let geoData = {
796806
parent: node.parentNode ? node.parentNode : "ROOT",
@@ -867,7 +877,9 @@ export const createCanvasSlice: StateCreator<MyState, [], [], CanvasSlice> = (
867877
get().deletePod(client, { id: change.id });
868878
get().buildNode2Children();
869879
// run auto-layout
870-
get().autoLayoutROOT();
880+
if (get().autoRunLayout) {
881+
get().autoLayoutROOT();
882+
}
871883
break;
872884
default:
873885
// should not reach here.
@@ -961,6 +973,7 @@ export const createCanvasSlice: StateCreator<MyState, [], [], CanvasSlice> = (
961973
},
962974
autoLayoutROOT: () => {
963975
// get all scopes,
976+
console.debug("autoLayoutROOT");
964977
let nodesMap = get().ydoc.getMap<Node>("pods");
965978
let nodes: Node[] = Array.from(nodesMap.values());
966979
nodes

0 commit comments

Comments
 (0)