Skip to content

Commit

Permalink
Improve frontend guideline (#23252)
Browse files Browse the repository at this point in the history
If an event listener must be `async`, the `e.preventDefault()` should be
before any `await`,
it's recommended to put it at the beginning of the function.
  • Loading branch information
wxiaoguang committed Mar 2, 2023
1 parent 294124d commit 0a9a3c2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/content/doc/developers/guidelines-frontend.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ It's not recommended to use `async` event listeners, which may lead to problems.
The reason is that the code after await is executed outside the event dispatch.
Reference: https://github.com/github/eslint-plugin-github/blob/main/docs/rules/async-preventdefault.md

If an event listener must be `async`, the `e.preventDefault()` should be before any `await`,
it's recommended to put it at the beginning of the function.

If we want to call an `async` function in a non-async context,
it's recommended to use `const _promise = asyncFoo()` to tell readers
that this is done by purpose, we want to call the async function and ignore the Promise.
Expand Down

0 comments on commit 0a9a3c2

Please sign in to comment.