Mithril Version: 1.1.6
When using m.request inside an oninit lifecycle method that returns a promise, Mithril does not redraw automatically in Chrome like it should when the request finishes and the promise resolves. It does work in Firefox and Safari.
- Chrome version: 75.0.3770.80
- Firefox version: 68.0b6
- Safari version: 12.1.1 (14607.2.6.1.1)
Expected Behavior
- Mithril should redraw automatically when an Ajax request finishes.
- Mithril should behave consistently between Chrome and Firefox at the very least.
Current Behavior
- The redraw callback is never called in Chrome.
Possible Solution
I tried stepping through Mithril in the browser debugger on Chrome and Firefox to figure out what is different between the two, and in Chrome it seems like this callback is never getting invoked: https://github.com/MithrilJS/mithril.js/blob/v1.1.6/request/request.js#L20-L26. Maybe Chrome does not allow reassigning then on a native Promise object? If that is the case, maybe there's some other way of doing this, like creating a new promise and wrapping the old one.
As a workaround, I am calling m.redraw() manually at the end of my oninit lifecycle in my actual application (company Intranet project).
Steps to Reproduce
Here is an example tiny app that reproduces the problem:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Demo</title>
</head>
<body>
<script src="https://unpkg.com/mithril@1.1.6/mithril.js"></script>
<script>
class Page {
async oninit(vnode) {
let response = await m.request("https://reqres.in/api/users/2");
this.user = response.data;
}
view(vnode) {
return m("main", [
m("h1", "Demo App"),
this.user ? m(User, {
user: this.user,
}) : "Loading..."
]);
}
}
class User {
view(vnode) {
return [
m("p", `Name: ${vnode.attrs.user.first_name} ${vnode.attrs.user.last_name}`),
m("p", `Email: ${vnode.attrs.user.email}`),
];
}
}
m.mount(document.body, Page);
</script>
</body>
</html>
In Firefox, this shows Loading... for a short time and then displays user information. On Chrome, this displays Loading... forever unless you call m.redraw() manually in the JavaScript console.
Context
Additional Information
Your Environment
- Browser Name and version: Chrome 75.0.3770.80
- Operating System and version (desktop or mobile): macOS Mojave 10.14.5
- Link to your project:
Mithril Version: 1.1.6
When using
m.requestinside anoninitlifecycle method that returns a promise, Mithril does not redraw automatically in Chrome like it should when the request finishes and the promise resolves. It does work in Firefox and Safari.Expected Behavior
Current Behavior
Possible Solution
I tried stepping through Mithril in the browser debugger on Chrome and Firefox to figure out what is different between the two, and in Chrome it seems like this callback is never getting invoked: https://github.com/MithrilJS/mithril.js/blob/v1.1.6/request/request.js#L20-L26. Maybe Chrome does not allow reassigning
thenon a nativePromiseobject? If that is the case, maybe there's some other way of doing this, like creating a new promise and wrapping the old one.As a workaround, I am calling
m.redraw()manually at the end of my oninit lifecycle in my actual application (company Intranet project).Steps to Reproduce
Here is an example tiny app that reproduces the problem:
In Firefox, this shows
Loading...for a short time and then displays user information. On Chrome, this displaysLoading...forever unless you callm.redraw()manually in the JavaScript console.Context
Additional Information
Your Environment