Skip to content

Conversation

@bytedream
Copy link
Contributor

Currently, when editing or deleting a file and the edit/commit form has changes, navigating the file tree will discard all changes without any warning. This PR prevents partial reloading when the edit form has unsaved changes, which will trigger a browser native warning dialog.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 11, 2025
@silverwind
Copy link
Member

silverwind commented Dec 11, 2025

So I understand that the JS would navigate to another entry, ignoring the "dirty form" state, and by adding this condition, it makes it skip the JS navigation via navigateTreeView and instead trigger a full-page load with the dirty checking done inside beforeunload by jquery.are-you-sure.

A better solution would be to make navigateTreeView perform the dirty checking and warning itself. That way, it will work without a disruptive full-page load when the user wants to discard their changes.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Dec 12, 2025

A better solution would be to make navigateTreeView perform the dirty checking and warning itself. That way, it will work without a disruptive full-page load when the user wants to discard their changes.

I don't think it is a must at the moment. are-you-sure.js module has many internal logic, since it is there, we should reuse that module, but not re-invent the wheel and write a new "are-you-sure" from scratch, unless you would replace the legacy "are-you-sure.js" completely


The "dirty check" (document.querySelector('.repo-view-content .form.dirty')) can be a helper function exported from the are-you-sure.js to make the code more stable and maintainable.

image

The real logic is here:

image

@silverwind
Copy link
Member

silverwind commented Dec 12, 2025

unless you would replace the legacy "are-you-sure.js" completely

Yes I think it's best to completely replace it with custom logic eventually. The plugin only works for full page navigation, while here we have a case of JS-based navigation (pushState and replaceState). It needs to support both forms of navigation.

The "dirty check" (document.querySelector('.repo-view-content .form.dirty')) can be a helper function exported from the are-you-sure.js to make the code more stable and maintainable.

Yes, this would be a good way to expose the dirty checking as a function used for JS-based navigation.

@silverwind
Copy link
Member

silverwind commented Dec 12, 2025

Oh and I still think the "unsaved warning" should eventually be replaced by a mechanism that automatically saves and restores unsaved content (based on URL) if the user decides to navigate back. E.g. like https://github.com/github/session-resume.

@bytedream
Copy link
Contributor Author

The "dirty check" (document.querySelector('.repo-view-content .form.dirty')) can be a helper function exported from the are-you-sure.js to make the code more stable and maintainable.

Sorry for the delay, I've relocated it to a helper function now

@silverwind
Copy link
Member

silverwind commented Dec 18, 2025

Tested it, works. I notice it does a full-page load after the popup is triggered, because it let's the onClick process normally and then the beforeunload event fires and is caught and the popup is displayed.

I think it could be optimized to do it without the full-page reload but that requires more changes in are-you-sure because it works by returning a string to beforeunload which triggers the message, while manual popup would need to be done with window.confirm.

So this is LGTM, and more improvements can be done later.

@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 Dec 18, 2025
@silverwind
Copy link
Member

I checked further: This specific browser popup can only be triggered by returning a string from beforeunload. The string is not actually displayed in at least Firefox and Chrome. Using window.confirm during beforeunload does not work and navigates away. So given the constraint the the popup is unchanged, this implementation with the full-page load is likely the only solution.

@wxiaoguang wxiaoguang force-pushed the edit-file-tree-full-reload branch from 05ef5d1 to d69a429 Compare December 18, 2025 14:16
@silverwind
Copy link
Member

@wxiaoguang approve?

@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 Dec 20, 2025
@silverwind
Copy link
Member

Tested again, still works.

@silverwind silverwind merged commit 05c3b84 into go-gitea:main Dec 20, 2025
24 checks passed
@GiteaBot GiteaBot added this to the 1.26.0 milestone Dec 20, 2025
silverwind added a commit to silverwind/gitea that referenced this pull request Dec 20, 2025
* origin/main:
  Show edit page confirmation dialog on tree view file change (go-gitea#36130)
  Fix regression in writing authorized principals (go-gitea#36213)
  [skip ci] Updated translations via Crowdin
  Convert locale files from ini to json format (go-gitea#35489)
  Bump crowdin/github-action from 1 to 2 (go-gitea#36204)
  Bump appleboy/git-push-action from 0.0.3 to 1.0.0 (go-gitea#36194)
  Fix labeler config for stylelint (go-gitea#36199)
  Add `modifies/dependencies` label to dependabot (go-gitea#36206)
  Add date to "No Contributions" tooltip (go-gitea#36190)
  Revert "Bump alpine to 3.23 (go-gitea#36185)" (go-gitea#36202)
  Add JSON linting (go-gitea#36192)
  Bump setup-node to v6, re-enable cache (go-gitea#36207)
  [skip ci] Updated translations via Crowdin
  Update chroma to v2.21.1 (go-gitea#36201)
  Disable dependabot automatic labels (go-gitea#36203)
  Bump astral-sh/setup-uv from 6 to 7 (go-gitea#36198)
  Front port changelog (go-gitea#36193)
  Bump dev-hanz-ops/install-gh-cli-action from 0.1.0 to 0.2.1 (go-gitea#36195)
  Bump aws-actions/configure-aws-credentials from 4 to 5 (go-gitea#36196)
  Bump docker/build-push-action from 5 to 6 (go-gitea#36197)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/frontend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants