Skip to content

Commit 517800f

Browse files
authored
Merge pull request #128 from cursor-js/fix/cursor-player-stop-cancels-queue
fix(core): cancel queued interactions when cursor player stops
2 parents 36f90c1 + 457db46 commit 517800f

8 files changed

Lines changed: 272 additions & 50 deletions

File tree

‎.changeset/seven-horns-listen.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cursor.js/core': patch
3+
---
4+
5+
Stop destroying cursors from letting in-flight typing and queued interactions continue after the player is stopped.

‎apps/docs/next.config.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@ if (!hasPro) {
2424
nextConfig.turbopack = {
2525
resolveAlias: {
2626
'@cursor.js/pro': path.resolve(process.cwd(), 'src/lib/pro-mock.ts'),
27+
'@cursor.js/pro/cursors': path.resolve(process.cwd(), 'src/lib/pro-mock.ts'),
2728
},
2829
};
2930

3031
// Fallback for Webpack (Production build 'next build')
3132
nextConfig.webpack = (config) => {
3233
config.resolve.alias['@cursor.js/pro'] = path.resolve(process.cwd(), 'src/lib/pro-mock.ts');
34+
config.resolve.alias['@cursor.js/pro/cursors'] = path.resolve(
35+
process.cwd(),
36+
'src/lib/pro-mock.ts',
37+
);
3338
return config;
3439
};
3540
}

‎packages/core/src/core/Cursor.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,38 @@ describe('Cursor', () => {
234234
expect(counter).toBe(3);
235235
});
236236

237+
it('.destroy() cancels the active step and prevents queued interactions from continuing', async () => {
238+
vi.spyOn(Math, 'random').mockReturnValue(0);
239+
240+
const actor = new Cursor({ humanize: false, speed: 1.0 });
241+
let clickCount = 0;
242+
btn.addEventListener('click', () => clickCount++);
243+
244+
const sequence = actor.type('#test-input', 'Hello', { delay: 20 }).click('#test-btn');
245+
246+
await new Promise((resolve) => setTimeout(resolve, 365));
247+
actor.destroy();
248+
await sequence;
249+
await new Promise((resolve) => setTimeout(resolve, 50));
250+
251+
expect(input.value.length).toBeLessThan('Hello'.length);
252+
expect(clickCount).toBe(0);
253+
});
254+
255+
it('.destroy() releases waitForEvent without running later steps', async () => {
256+
const actor = new Cursor({ humanize: false });
257+
let counter = 0;
258+
259+
const sequence = actor.waitForEvent('#test-btn', 'custom-event').do(() => counter++);
260+
261+
await new Promise((resolve) => setTimeout(resolve, 20));
262+
actor.destroy();
263+
await sequence;
264+
await new Promise((resolve) => setTimeout(resolve, 20));
265+
266+
expect(counter).toBe(0);
267+
});
268+
237269
it('.waitForEvent() pauses the queue until the specified event is dispatched', async () => {
238270
const actor = new Cursor({ humanize: false });
239271
let counter = 0;

0 commit comments

Comments
 (0)