Skip to content

Commit 0739693

Browse files
committed
fix: use replace options method for improved hmr support
1 parent 00d6fd0 commit 0739693

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

packages/react/src/hooks/useAdhesive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ export function useAdhesive(
7676
}, [target]);
7777

7878
useEffect(() => {
79-
adhesive.current?.updateOptions(getValidatedOptions());
79+
adhesive.current?.replaceOptions(getValidatedOptions());
8080
}, [options]);
8181
}

packages/vue/src/composables/useAdhesive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,6 @@ export function useAdhesive(
106106

107107
watch(
108108
() => toValue(options),
109-
() => adhesive?.updateOptions(getValidatedOptions()),
109+
() => adhesive?.replaceOptions(getValidatedOptions()),
110110
);
111111
}

packages/vue/src/directives/vAdhesive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ export const vAdhesive: AdhesiveDirective = {
7373
const options = binding.value;
7474
const position = binding.arg || options?.position;
7575

76-
el.__adhesive__?.updateOptions({ ...options, position });
76+
el.__adhesive__?.replaceOptions({ ...options, position });
7777
},
7878
};

test/unit/react.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describe("React Integration", () => {
172172
).toBeInTheDocument();
173173
});
174174

175-
it("calls updateOptions when options change", async () => {
175+
it("calls replaceOptions when options change", async () => {
176176
const user = userEvent.setup();
177177
renderTestComponent();
178178
const {
@@ -181,24 +181,24 @@ describe("React Integration", () => {
181181
toggleOffsetButton,
182182
} = getTestElements();
183183

184-
mockAdhesiveInstance.updateOptions.mockClear();
184+
mockAdhesiveInstance.replaceOptions.mockClear();
185185

186186
await user.click(toggleEnabledButton);
187-
expect(mockAdhesiveInstance.updateOptions).toHaveBeenCalledWith(
187+
expect(mockAdhesiveInstance.replaceOptions).toHaveBeenCalledWith(
188188
expect.objectContaining({
189189
enabled: false,
190190
}),
191191
);
192192

193193
await user.click(togglePositionButton);
194-
expect(mockAdhesiveInstance.updateOptions).toHaveBeenCalledWith(
194+
expect(mockAdhesiveInstance.replaceOptions).toHaveBeenCalledWith(
195195
expect.objectContaining({
196196
position: "bottom",
197197
}),
198198
);
199199

200200
await user.click(toggleOffsetButton);
201-
expect(mockAdhesiveInstance.updateOptions).toHaveBeenCalledWith(
201+
expect(mockAdhesiveInstance.replaceOptions).toHaveBeenCalledWith(
202202
expect.objectContaining({
203203
offset: TEST_OFFSETS[2],
204204
}),

test/unit/vue.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,30 +169,30 @@ describe("Vue Integration", () => {
169169
expect(offsetButton).toHaveTextContent("10");
170170
});
171171

172-
it("calls updateOptions when options change", async () => {
172+
it("calls replaceOptions when options change", async () => {
173173
const { getByTestId } = renderTestComponent();
174174
const toggleEnabledButton = getByTestId("toggle-enabled");
175175
const togglePositionButton = getByTestId("toggle-position");
176176
const toggleOffsetButton = getByTestId("toggle-offset");
177177

178-
mockAdhesiveInstance.updateOptions.mockClear();
178+
mockAdhesiveInstance.replaceOptions.mockClear();
179179

180180
await fireEvent.click(toggleEnabledButton);
181-
expect(mockAdhesiveInstance.updateOptions).toHaveBeenCalledWith(
181+
expect(mockAdhesiveInstance.replaceOptions).toHaveBeenCalledWith(
182182
expect.objectContaining({
183183
enabled: false,
184184
}),
185185
);
186186

187187
await fireEvent.click(togglePositionButton);
188-
expect(mockAdhesiveInstance.updateOptions).toHaveBeenCalledWith(
188+
expect(mockAdhesiveInstance.replaceOptions).toHaveBeenCalledWith(
189189
expect.objectContaining({
190190
position: "bottom",
191191
}),
192192
);
193193

194194
await fireEvent.click(toggleOffsetButton);
195-
expect(mockAdhesiveInstance.updateOptions).toHaveBeenCalledWith(
195+
expect(mockAdhesiveInstance.replaceOptions).toHaveBeenCalledWith(
196196
expect.objectContaining({
197197
offset: TEST_OFFSETS[2],
198198
}),
@@ -496,26 +496,26 @@ describe("Vue Integration", () => {
496496
expect(getByTestId("toggle-enabled")).toHaveTextContent("Disable");
497497
expect(getByTestId("change-offset")).toHaveTextContent("Offset: 10");
498498

499-
mockAdhesiveInstance.updateOptions.mockClear();
499+
mockAdhesiveInstance.replaceOptions.mockClear();
500500

501501
await fireEvent.click(getByTestId("toggle-enabled"));
502502
expect(getByTestId("toggle-enabled")).toHaveTextContent("Enable");
503-
expect(mockAdhesiveInstance.updateOptions).toHaveBeenCalledWith(
503+
expect(mockAdhesiveInstance.replaceOptions).toHaveBeenCalledWith(
504504
expect.objectContaining({
505505
enabled: false,
506506
}),
507507
);
508508

509509
await fireEvent.click(getByTestId("change-offset"));
510510
expect(getByTestId("change-offset")).toHaveTextContent("Offset: 30");
511-
expect(mockAdhesiveInstance.updateOptions).toHaveBeenCalledWith(
511+
expect(mockAdhesiveInstance.replaceOptions).toHaveBeenCalledWith(
512512
expect.objectContaining({
513513
offset: 30,
514514
}),
515515
);
516516
});
517517

518-
it("calls updateOptions when directive value changes", async () => {
518+
it("calls replaceOptions when directive value changes", async () => {
519519
const TestComponent = createTestApp(
520520
`
521521
<div>
@@ -547,11 +547,11 @@ describe("Vue Integration", () => {
547547
},
548548
});
549549

550-
mockAdhesiveInstance.updateOptions.mockClear();
550+
mockAdhesiveInstance.replaceOptions.mockClear();
551551

552552
await fireEvent.click(getByTestId("increment-offset"));
553553

554-
expect(mockAdhesiveInstance.updateOptions).toHaveBeenCalledWith(
554+
expect(mockAdhesiveInstance.replaceOptions).toHaveBeenCalledWith(
555555
expect.objectContaining({
556556
offset: 20,
557557
}),

0 commit comments

Comments
 (0)