Skip to content

Commit

Permalink
Fix minor issue in commitUpdate() (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon authored Sep 1, 2022
1 parent 805dac3 commit 15e7828
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
12 changes: 11 additions & 1 deletion package/src/renderer/HostConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,17 @@ export const skHostConfig: SkiaHostConfig = {
return;
}
bustBranchMemoization(instance);
instance.props = nextProps;
if (instance instanceof DrawingNode) {
const { onDraw, skipProcessing, ...props } = nextProps;
instance.props = props;
} else if (instance instanceof DeclarationNode) {
const { onDeclare, ...props } = nextProps;
instance.props = props;
} else {
throw new Error(
"Unsupported instance commitUpdate " + instance.constructor.name
);
}
},

commitTextUpdate: (
Expand Down
2 changes: 1 addition & 1 deletion package/src/renderer/__tests__/setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,5 @@ export const mountCanvas = (element: ReactNode) => {
center: Skia.Point(width / 2, height / 2),
Skia,
};
return { draw: () => container.draw(ctx), surface };
return { draw: () => container.draw(ctx), surface, container };
};
6 changes: 5 additions & 1 deletion package/src/values/hooks/__tests__/useComputedValue.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe("useComputedValue", () => {
const id1 = global.SkiaValueApi.createValue(0);
const id2 = global.SkiaValueApi.createValue(1);
// We draw
const { surface, draw } = mountCanvas(
const { surface, draw, container } = mountCanvas(
<TestComputedDeps id1={id1} id2={id2} />
);
draw();
Expand All @@ -70,6 +70,10 @@ describe("useComputedValue", () => {
draw();
processResult(surface, "snapshots/animations/green.png");
expect(counter.value).toBe(2);
expect(container.children.length).toBe(1);
const props = container.children[0].props as Record<string, unknown>;
expect(props.onDraw).not.toBeDefined();
expect(Object.keys(props).length).toBe(1);
});

it("should clean up stable version", async () => {
Expand Down

0 comments on commit 15e7828

Please sign in to comment.