Skip to content

Wrong async/await/preventDefault usage #17448

@wxiaoguang

Description

@wxiaoguang

This is an issue for discussion of frontend refactoring. @lafriks @silverwind

The code https://github.com/go-gitea/gitea/blob/main/web_src/js/features/repo-legacy.js#L350 works like this:

$(document).on('click', '.edit-content', async function (event) {
    await createDropzone();
    event.preventDefault();
});

// equal to 
$(document).on('click', '.edit-content', function (event) {
    return Promise.resolve(createDropzone).then(() => {
        event.preventDefault();
    });
});

The usage of async/await is incorrect. The preventDefault won't have effect because the event has been processed synchronously before (when the listener returned).

So, that's why I insist to clean up most inconsistent await/async in the code base, only use them when it is necessary.

We should do our best to make everything work as expected.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic/uiChange the appearance of the Gitea UItype/proposalThe new feature has not been accepted yet but needs to be discussed first.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions