Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dropzone JS error when attachment is disabled #31486

Merged
merged 2 commits into from
Jun 26, 2024

Conversation

wxiaoguang
Copy link
Contributor

Fix #31485

@GiteaBot GiteaBot added this to the 1.22.1 milestone Jun 25, 2024
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 25, 2024
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jun 25, 2024
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 25, 2024
@silverwind
Copy link
Member

silverwind commented Jun 25, 2024

What was the JS error? dropzoneInst?.element not existant?

@silverwind
Copy link
Member

Actually I'm not sure the fix is correct because querySelectorAll result is always iterable, even if empty. Would the proper fix not be dropzoneInst?.element.querySelectorAll in case the error was that the element did not exist?

@silverwind silverwind self-requested a review June 25, 2024 17:04
@GiteaBot GiteaBot added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 25, 2024
@ukct
Copy link

ukct commented Jun 25, 2024

The specific error thrown is
un?.element.querySelectorAll is not iterable (cannot read property Symbol(Symbol.iterator))

dropzoneInst is null when it fails.

@silverwind
Copy link
Member

I can't seem to reproduce the original issue on either main branch or 1.22 branch with attachment.ENABLE = false.

All I can say for sure is that this ?? [] does nothing because querySelectorAll results are guaranteed to be iterable, so the root cause must be something else.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 26, 2024
@wxiaoguang
Copy link
Contributor Author

wxiaoguang commented Jun 26, 2024

I can't seem to reproduce the original issue on either main branch or 1.22 branch with attachment.ENABLE = false.

All I can say for sure is that this ?? [] does nothing because querySelectorAll results are guaranteed to be iterable, so the root cause must be something else.

  1. The root regression is Remove jQuery .map() and enable eslint rules for it #29272, it breaks the dropzone uploading, and it caused the null access because dz is null if the attachment is disabled.
  2. Some following up changes didn't completely fix the null problem when the attachment is disabled, foo?.bar() always returns undefined if foo doesn't exist, no matter what bar() does.

@silverwind
Copy link
Member

silverwind commented Jun 26, 2024

Please explain how this addition of ?? [] fixes anything here. As I see it, querySelectorAll can not return null or undefined so that fallback would never activate.

@wxiaoguang
Copy link
Contributor Author

Please explain how this addition of ?? [] fixes anything here. As I see it, querySelectorAll can not return null or undefined so that fallback would never activate.

I have explained it above:

`foo?.bar()` always returns undefined if `foo` doesn't exist, no matter what `bar()` does.

Could you just try it by yourself?

const el = null; for (const x of el?.foo.bar()) {}

@silverwind
Copy link
Member

Ah I understand now. Yes when the optional chain is triggered, we need the fallback.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 26, 2024
@wxiaoguang wxiaoguang merged commit 151b786 into go-gitea:release/v1.22 Jun 26, 2024
26 checks passed
@wxiaoguang wxiaoguang deleted the fix-attachment-dropzone branch June 26, 2024 10:09
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Sep 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/js size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants