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

onbeforeremove should tolerate thenables that synchronously resolve #2592

Closed
dead-claudia opened this issue May 2, 2020 · 1 comment · Fixed by #3005
Closed

onbeforeremove should tolerate thenables that synchronously resolve #2592

dead-claudia opened this issue May 2, 2020 · 1 comment · Fixed by #3005
Assignees
Labels
Area: Core For anything dealing with Mithril core itself Type: Bug For bugs and any other unexpected breakage

Comments

@dead-claudia
Copy link
Member

Mithril version: v2.0.4 (not new, though)

Browser and OS: All

Project:

Code

const Comp = {
	view: () => m("div"),
	onbeforeremove: () => {
		then(resolve, reject) {
			resolve(delay(100))
		},
	},
}

function delay(ms) {
	return new Promise(resolve => { setTimeout(resolve, ms) })
}

Steps to Reproduce

Expected Behavior

It to operate asynchronously

Current Behavior

It doesn't wait.

Context

We're not honoring the Promises/A+ spec here. And fixing this is as simple as changing these two lines to wrap their this value with Promise.resolve(...).

@dead-claudia dead-claudia added Type: Bug For bugs and any other unexpected breakage Area: Core For anything dealing with Mithril core itself labels May 2, 2020
@dead-claudia dead-claudia self-assigned this May 2, 2020
@dead-claudia dead-claudia moved this to Low priority in Triage/bugs Sep 2, 2024
@dead-claudia dead-claudia mentioned this issue Oct 13, 2024
8 tasks
@kfule
Copy link
Contributor

kfule commented Jan 27, 2025

Currently, mithril uses finally() instead of then() to handle onbeforeremove, so a simple thenable object seems to cause an error. (flems)
(Implementing finally() in thenable objects reproduces the not-waiting problem as described. (flems) This is no longer a proper test code, though.)

Anyway, it seems to me that wrapping the stateResult and attrsResult in Promise.resolve() would be a good solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Core For anything dealing with Mithril core itself Type: Bug For bugs and any other unexpected breakage
Projects
Status: Closed
Development

Successfully merging a pull request may close this issue.

2 participants