Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: clearTimeout being called with argument 'undefined' #5001

Closed
arlyon opened this issue Jul 28, 2024 · 0 comments · Fixed by #5002
Closed

Bug: clearTimeout being called with argument 'undefined' #5001

arlyon opened this issue Jul 28, 2024 · 0 comments · Fixed by #5002
Labels

Comments

@arlyon
Copy link

arlyon commented Jul 28, 2024

XState version

XState version 5

Description

I am trying to integrate temporal and xstate 5 which I have working bar a few minor roadblocks. Temporal overrides clearTimeout which calls into their runtime however it crashes because xstate has a habit of calling clearTimeout with undefined. Temporal then tries to find a timer with id 0 (presumably coercing undefined across the FFI boundary) and erroring out because it doesn't exist. A workaround is to override this:

const clearTimeoutInner = global.clearTimeout;

/**
 * xstate passes undefined here, which temporal doesn't like
 * instead, we intercept and log it
 *
 * @param id
 */
global.clearTimeout = (id) => {
	if (id !== undefined) {
		clearTimeoutInner(id);
	} else {
		console.log("INVALID TIMEOUT");
	}
};

However, this seems like a bug as I don't think clearTimeout should ever be called with no arguments. From testing, xstate does still correctly cancel all the timers as it should. I do not know the cause of the extra invalid calls.

Expected result

Do not call clearTimeout with undefined.

Actual result

When timers elapse, clearTimeout is called with undefined.

Reproduction

https://codesandbox.io/p/live/c4801092-33a5-4d8e-9e9f-366078f138ab

Open up the sandbox, see the console print undefined.

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant