diff options
author | wxiaoguang | 2023-03-03 00:46:47 +0800 |
---|---|---|
committer | GitHub | 2023-03-02 11:46:47 -0500 |
commit | 0a9a3c2a6df00dec405da1d8d07f1f72548e9e7b (patch) | |
tree | 90558ef38e8f01cc78b01ce5ca675d1fa032658b /docs | |
parent | 294124d129b12673109767abd331c78c71e3bf2c (diff) |
Improve frontend guideline (#23252)
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.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/content/doc/developers/guidelines-frontend.en-us.md | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/docs/content/doc/developers/guidelines-frontend.en-us.md b/docs/content/doc/developers/guidelines-frontend.en-us.md index 7f4d87d90..66d3e83e9 100644 --- a/docs/content/doc/developers/guidelines-frontend.en-us.md +++ b/docs/content/doc/developers/guidelines-frontend.en-us.md @@ -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. |