emberjs / emberjs/ember.js

[Bug] Bug report - Using async/await on the model hook of a route never renders

Open
#19,679 5 comments 0 reactions 0 assignees View on GitHub
Routing
Dominant language
TypeScript
Stars
22.6k
Forks
4.2k
Avg merge
3d 12h
Merged PRs (30d)
15

Description

### 🐞 Describe the Bug

A route's `model` hook is asynchronous by nature. When it returns a `thenable` object it waits for said promise to resolve _and then_ continues

In my case I turned the model hook into an async function and returned a simple `this.transitionTo('foo')` and noticed the
app does not continue to render, it does not display errors either.

```js
export default Route.extend({
async model() {
return this.transitionTo('foo');
}
});

```

### 🔬 Minimal Reproduction

Here's my dummy app reproducing the error https://github.com/mariogintili/async-model

- Clone my app
- Run `ember s`
- Visit `localhost:4200`
- See the application not rendering

### 😕 Actual Behavior

Nothing renders, it seems as if the promise never resolves?

### 🤔 Expected Behavior

For the promise to resolve and subsecuently redirect or at least display an error

### 🌍 Environment

```shell
$ ember --version
ember-cli: 3.25.3
node: 14.2.0
os: darwin x64
```

### Additional context

- the dummy app's router https://github.com/mariogintili/async-model/blob/main/app/router.js
- the dummy app's application route https://github.com/mariogintili/async-model/blob/main/app/routes/application.js#L4

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.