Skip to content

web: migrate the repository file editor pages to React - #8532

Merged
unknwon merged 4 commits into
mainfrom
editor-react-flamego
Nov 16, 2026
Merged

unknwon merged 4 commits into
mainfrom
editor-react-flamego

Conversation

@unknwon

@unknwon unknwon commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Describe the pull request

Migrates the repository file editor to React: editing a file (/{owner}/{repo}/_edit/{branch}/{path}), creating one (/_new/{branch}/{dir}), deleting one (/_delete/{branch}/{path}) and uploading files (/_upload/{branch}/{dir}). They are backed by /api/web/{owner}/{repo}/editor. SimpleMDE and CodeMirror 5 are removed from Gogs, so CodeEditor (CodeMirror 6) is the only editor left.

  • Access is the same as legacy. Only writers of a non-empty repository that is not a mirror get the pages. Signed-out visitors are sent to sign in, and everyone else gets 404. A branch that only takes pull requests is not found. Upload is not found when uploads are disabled.
  • Edit and new file: a path field that works like a breadcrumb (typing / adds a directory and Backspace at the start removes it), then the editor. The language follows the file name as you type it, e.g., renaming to main.go switches to Go with line numbers. Markdown files get a Preview tab. Edits get a Preview changes tab, a diff rendered in the browser with @pierre/diffs, like the commit page.
  • Commit form, shared by all four pages: summary with the default message as its placeholder, an extended description, and committing directly or to a new branch. A new branch leads to the compare page when pull requests are allowed.
  • Indentation follows the .editorconfig of the branch being edited: tabs or spaces, the indent size and the tab width, for the file name as it is typed. GET /editor-indent?branch=&path= answers it. Without rules, Tab indents by two spaces. Typing a closing brace moves the line back to its indentation.
  • Conflicts: if the file changed since the editor opened, the page says so with a link to the changes, and committing again overwrites them, like legacy.
  • Upload: a drop zone that also opens the file picker, uploaded files listed with remove buttons, and a directory field. Removing a file deletes it from the server.
  • Server: GET /editor/{branch}/{path} describes the branch and the path, then POST /editor/files, /editor/delete, /editor/upload, and POST/DELETE /editor/uploads. The JSON routes take 10 MiB at most, and uploads keep [repository.upload] FILE_MAX_SIZE.
  • Removed: internal/route/repo/editor.go, the repo/editor/* templates, the _preview, upload-file and upload-remove routes, database.GetDiffPreview, git.DiffCached, the editor form structs, RequireSimpleMDE, public/plugins/simplemde-1.10.1, public/plugins/codemirror-5.17.0, and about 360 lines of editor scripts in gogs.js.
  • Sentence-cased "Preview changes" and "Commit changes". Added editor.commit_summary, commit_description, new_branch_name, invalid_branch_name, file_path, directory, delete_file and no_files_to_upload.

Behavior changes from legacy

  • The diff in Preview changes is computed in the browser. The server endpoint for it is gone.
  • .editorconfig is read from the branch being edited rather than the default branch, and matched against the whole path, so sections like [docs/**.md] apply.
  • A file can be saved empty. Legacy required content.
  • A new branch name is checked with git check-ref-format instead of the alphanumeric, dash, dot and slash rule.
  • Uploading with no files is an error on the drop zone. Legacy silently committed nothing.
  • Paths and branches in the page you land on after a commit are escaped, so a file named a#b.go opens.
  • A new branch named after the branch being edited is refused as an existing branch. Legacy committed to the branch being edited.
  • Deleting a file lands on the closest directory that is left, since directories that only held the file go away with it. Legacy went to the root of the branch.
  • Uploading to the root of the repository defaults the summary to "Upload files to '/'". Legacy left the quotes empty.

Screenshots

Editing a Markdown file

Editing a Markdown file

Preview changes

Preview changes

Markdown preview

Markdown preview

Preview changes, dark

Preview changes, dark

The file changed while editing

The file changed while editing

New Go file in new directories, indented with tabs by .editorconfig, to a new branch

New Go file in new directories, to a new branch

New branch name already taken, here the branch being edited

New branch name already taken

Deleting a file

Deleting a file

Uploading files

Uploading files

Editing to a new branch, 375px
Editing to a new branch, 375px
Uploading, 375px
Uploading, 375px

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code and provided the test plan below.
  • I have added an entry to CHANGELOG.

Test plan

  1. go test ./cmd/gogs/internal/web/ ./internal/route/... ./internal/database/ ./internal/git/ passes, and TestRequireSignIn covers the new endpoint. moon run gogs:lint and moon run web:lint report 0 issues.
  2. Ran a -tags prod build with SQLite. Seed: alice owns the public widgets, the empty empty and the private secret. bob can write to secret only, and carol has no access.
  3. Access: bob gets 404 from the pages and endpoints of widgets, carol from secret, and alice from empty. Signed-out visitors get 401 from the endpoints, and all four pages redirect to sign in. A missing branch and feature/login, which only takes pull requests, get 404. A symlink cannot be edited, deleted or used as a directory.
  4. Commits, checked with git log in the bare repository: edited README.md, renamed etc/x to etc/y.txt, created docs/cmd/server/main.go in new directories, deleted docs/a#b.go, and uploaded two files to the new docs/drafts. The summary and description became the commit message, and an empty summary used the default. A new branch alice-patch-2 led to /compare/master...alice:alice-patch-2. An existing branch name, a path that is a directory, renaming onto README.md and ../../etc/x were refused or cleaned with field messages. A file over 3 MB gets 413.
  5. Indentation: with an .editorconfig on master, main.go gets tabs 8 wide, ci.yml two spaces, docs/a.md three, and other files four. A branch without one gets no rules. Missing and pull-request-only branches get 404, bob gets 404 and signed-out visitors 401. In the browser, Tab in main.go inserts a tab, and renaming the file to ci.yml and then notes.txt switches Tab to two and four spaces.
  6. Browser, at 1280, dark and 375: changed README behind an open editor, got the conflict message, then committed again and landed on the file. Checked the Markdown preview and the diff, the path breadcrumb with / and Backspace, Go highlighting after typing the name, the new branch error, and removing an upload. No sideways scroll at 375.
  7. Browser, again on alice/alpha with an .editorconfig (tabs for *.go, two spaces for YAML, four otherwise):
    • Appended a section to docs/guide.md, checked Preview (heading, list, tip alert, table) and Preview changes in light and dark, then bob changed the file behind the editor. Committing showed the conflict notice, and committing again overwrote it.
    • Typed cmd/worker/run.go into the path field, which became alpha / cmd / worker / run.go. In the editor, Enter after { indented with a tab and } moved back. Naming the new branch main showed "Branch 'main' already exists in this repository." alice-worker-run led to /compare/main...alice:alice-worker-run, and git show has the file with tabs.
    • Deleting deep/a/b/only.go landed on /src/main/deep, sib/one.txt (with a sibling) on /src/main/sib, and a file whose directory only held it on the root. The delete button is solid red.
    • Uploading with no files showed "Choose at least one file to upload." Uploaded two files to the new docs/drafts, removed one copy of a duplicate, and found both files committed and no uploads left in the database. Uploading to the root committed "Upload files to '/'".
    • bob gets 404 from _edit, _new, _upload and the delete endpoint of alice's repository, and signed-out visitors are sent to sign in. Nothing scrolls sideways at 375.

unknwon added a commit that referenced this pull request Nov 13, 2026
@unknwon
unknwon added this pull request to stack #8457 November 13, 2026 04:21
@unknwon
unknwon force-pushed the editor-react-flamego branch 2 times, most recently from 284a228 to a55b369 Compare November 14, 2026 05:43
@unknwon
unknwon force-pushed the editor-react-flamego branch 2 times, most recently from 60b1992 to e546371 Compare November 14, 2026 07:11
@unknwon
unknwon force-pushed the editor-react-flamego branch 4 times, most recently from 90887b8 to febb16a Compare November 14, 2026 17:11
@unknwon
unknwon force-pushed the editor-react-flamego branch 2 times, most recently from a6c746c to 2eaadf9 Compare November 14, 2026 19:00
@unknwon
unknwon force-pushed the editor-react-flamego branch 2 times, most recently from 5308567 to ed2ef35 Compare November 14, 2026 19:34
@unknwon
unknwon force-pushed the editor-react-flamego branch 7 times, most recently from bb15e15 to a5dda87 Compare November 14, 2026 23:00
@unknwon
unknwon force-pushed the editor-react-flamego branch 4 times, most recently from 0b552d0 to a1238dd Compare November 15, 2026 02:17
@unknwon
unknwon force-pushed the editor-react-flamego branch 7 times, most recently from 5bb293c to 97e6d6b Compare November 15, 2026 05:34
@unknwon
unknwon force-pushed the editor-react-flamego branch 6 times, most recently from afc10ce to e19c1f5 Compare November 16, 2026 00:46
Base automatically changed from wiki-react-flamego to main November 16, 2026 01:34
@unknwon
unknwon force-pushed the editor-react-flamego branch from e19c1f5 to 285c2eb Compare November 16, 2026 01:34
@unknwon
unknwon marked this pull request as ready for review November 16, 2026 01:34
Editing, creating, deleting and uploading files of a branch are now React
pages backed by /api/web/{owner}/{repo}/editor. Code and Markdown are edited
in CodeEditor, which now follows the file name as it changes, and the changes
are previewed as a diff in the browser.

SimpleMDE and CodeMirror 5 are gone, along with the server-rendered editor,
its diff preview endpoint and the scripts that drove them.
The editor asks the branch's .editorconfig how to indent the file being
edited, and follows it as the file name changes: tabs or spaces, the indent
size and the tab width.
…tation

- A new branch named after the branch being edited is refused as an
  existing branch instead of committing to it.
- Deleting a file lands on the closest directory that is left, since
  directories that only held the file go away with it.
- Typing a closing brace moves the line back to its indentation.
- Cancel is an outline button, and uploading to the root defaults the
  summary to "Upload files to '/'".
@unknwon
unknwon force-pushed the editor-react-flamego branch from 4f5b1e5 to 982019f Compare November 16, 2026 02:39
The editor's Preview tab rendered a Markdown file like an issue, which
keeps line breaks since #8607, with links resolved against the
repository root. It now renders like the file does, with links and
images resolved against its directory, as the legacy editor did.
@unknwon
unknwon merged commit c9fdfcf into main Nov 16, 2026
12 checks passed
@unknwon
unknwon deleted the editor-react-flamego branch November 16, 2026 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant