should I care about "Zone.js does not support native async/await in ES2017."?

The accepted answer is correct, but to be more specific, per this longstanding issue on GitHub, if you target es2015, your async functions will be transpiled to use a helper function called _awaiter, which uses a generator function under the hood. Because of technical constraints outlined at the above link, it is possible for Zone.js to hook the generator function and manage its execution in its own microtask queue, but it is not possible to do so for a native await statement.

The net result is that, if your function is executing in the context of Zone A, then you hit an await statement, when the next line of your function finally executes, it will be in the Root Zone. From that issue:

const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
const test = async () => {
      console.log(Zone.current.name) // will output 'angular'
      await delay(100);
      console.log(Zone.current.name) // will output 'root'
    }

I believe that this also means that any Zone feature that allows you to manage task execution (like the Angular test helpers fakeAsync / tick / flush) will fail to correctly recognize the "task" (of waiting for the await to resolve) as pending. (Which, of course, is why this is a problem in the first place.)


I agree with Andrei. It might not update your component, especially if you're getting the data from an API somewhere. To solve this, you could change the target in your tsconfig.base.json file back to es2015.

Tags:

Angular

Zonejs