Skip to content
Open
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
Empty file added .jules/bolt.md
Empty file.
54 changes: 30 additions & 24 deletions client/src/QueueEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,38 @@ import * as types from "./types";
import * as utils from "./utils";
import TopButton from "./TopButton";

export const QueueEntry = (props: {
node_id: types.TNodeId;
index: number;
}) => {
const exists = useRawSelector((state) =>
Object.hasOwn(state.data.nodes, props.node_id),
);
return exists ? (
<_QueueEntry node_id={props.node_id} index={props.index} />
) : (
<div className="w-[1px] h-[1px]" /> // `null` is not allowed as Virtuoso does not allow 0-height elements.
);
};
export const QueueEntry = React.memo(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add coverage for the memoized render behavior

Add a component test that verifies a parent-only rerender is skipped while Redux changes to node existence or status still update the entry. This commit introduces two memoization boundaries without any corresponding test, leaving both the intended optimization and the selector-driven update behavior unprotected despite the repository requirement to add tests for changes.

AGENTS.md reference: AGENTS.md:L3-L3

Useful? React with πŸ‘Β / πŸ‘Ž.

(props: { node_id: types.TNodeId; index: number }) => {
// ⚑ Bolt: Memoize QueueEntry to prevent unnecessary re-renders of virtualized list items
// when parent components update, significantly reducing React render times during scrolling.
const exists = useRawSelector((state) =>
Object.hasOwn(state.data.nodes, props.node_id),
);
return exists ? (
<_QueueEntry node_id={props.node_id} index={props.index} />
) : (
<div className="w-[1px] h-[1px]" /> // `null` is not allowed as Virtuoso does not allow 0-height elements.
);
},
);
QueueEntry.displayName = "QueueEntry";

const _QueueEntry = (props: { node_id: types.TNodeId; index: number }) => {
const isTodo =
utils.assertV(
useSelector((state) => state.swapped_nodes.status?.[props.node_id]),
) === "todo";
const _QueueEntry = React.memo(
(props: { node_id: types.TNodeId; index: number }) => {
// ⚑ Bolt: Memoize internal _QueueEntry to avoid cascading renders.
const isTodo =
utils.assertV(
useSelector((state) => state.swapped_nodes.status?.[props.node_id]),
) === "todo";

return isTodo ? (
<TodoQueueEntry node_id={props.node_id} index={props.index} />
) : (
<NonTodoQueueEntry node_id={props.node_id} index={props.index} />
);
};
return isTodo ? (
<TodoQueueEntry node_id={props.node_id} index={props.index} />
) : (
<NonTodoQueueEntry node_id={props.node_id} index={props.index} />
);
},
);
_QueueEntry.displayName = "_QueueEntry";

const NonTodoQueueEntry = (props: {
node_id: types.TNodeId;
Expand Down
Loading