Skip to content

web: migrate the repository code browser to React - #8536

Merged
unknwon merged 6 commits into
mainfrom
code-react-flamego
Nov 16, 2026
Merged

unknwon merged 6 commits into
mainfrom
code-react-flamego

Conversation

@unknwon

@unknwon unknwon commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Describe the pull request

Migrates the repository code browser to React: the repository home (/{owner}/{repo}) and the files at a branch, a tag or a commit (/{owner}/{repo}/src/{ref}/{path}). Both are backed by GET /api/web/{owner}/{repo}/src/{ref}/{path}, which resolves the ref like the commit history (the shortest leading part that names a branch or a tag, else a commit SHA, else the default branch).

  • Access is the same as legacy. Readers see the code, and everyone else gets 404. Guests of a partly public repository are still redirected to its issues or wiki by the server.
  • Directory: a latest-commit bar (author, subject with issue links, SHA, time, and "N Commits" at the root or "History" below it), then the entries with their last commit and time: directories, files with the same Pierre icons as the diff file tree, symlinks, and submodules linking to their repository @ sha. A ".." row goes up. The first README is shown below, rendered for Markdown and Org mode and as text otherwise.
  • Root: the description and website ("No description" when empty), branch and release counts (singular for one), and a "Code" menu with the clone URL (HTTP or SSH, remembered under the same localStorage key as legacy) and ZIP and TAR.GZ downloads.
  • File: a header with the line count and size, Permalink (off a commit), Raw, and Edit and Delete links into the editor from web: migrate the repository file editor pages to React #8532. They are disabled with the legacy reasons: off a branch, without write access, a non-text file, or a symlink. The body depends on the file:
    • Text is highlighted with line numbers and the tab width from .editorconfig. In dark mode, punctuation is lifted from Pierre's #636363 and selected lines are tinted less, so code on them stays above 4.5:1. Clicking or dragging over line numbers writes #L5 or #L5-L9, and opening such a link highlights the lines and scrolls to them.
    • Markdown and Org mode are rendered, and code blocks in them are highlighted. Like GitHub, they and notebooks have Preview and Code buttons, and Code (?plain=1) shows the highlighted source with line numbers and line selection.
    • Jupyter notebooks still render with notebook.js through the server sanitizer, and their input cells are highlighted.
    • Images, videos and PDFs (pdf.js) show inline.
    • Binary files and text over MAX_DISPLAY_FILE_SIZE link to the raw file.
  • Toolbar: RefPicker keeps the path when switching refs, and a breadcrumb links every directory. Writers on an editable branch get "New file" and "Upload file". When the viewer can open a pull request, a compare button goes to the base repository with the same rules as legacy (forks compare against their base).
  • Empty repository: writers of a non-mirror see the quick guide with the clone box and the push commands, highlighted. The commands use the URL of the protocol picked in the clone box, as legacy did. Others see "This repository does not have any content yet."
  • README images: /raw/ serves .svg as image/svg+xml with Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox, so relative SVG images load and an SVG opened directly cannot run scripts. Images ending in #gh-light-mode-only or #gh-dark-mode-only show only in that theme, as on GitHub.
  • Removed: the legacy repo.Home handler (view.go) and the home, view_list, view_file, empty and branch_dropdown templates, and the notebook <script> tags in base/head.tmpl, which only these pages used. CloneBox moved out of the wiki page so both pages share it, and editorconfigIndent is now shared by the editor and the file view.
  • Added repo.file_preview, repo.file_view_mode, repo.code, repo.commit, repo.release, repo.download_archive, repo.file_line and repo.file_lines. Sentence-cased "No description", "Quick guide" and "Compare changes".

Behavior changes from legacy

  • The README of a directory that is not Markdown or Org mode is shown as preformatted text. Legacy turned its newlines into <br> and showed the rest as HTML.
  • Selecting lines uses clicks and drags on line numbers. Legacy used shift-click for ranges.
  • The root shows the commit count in the latest-commit bar, and the branch and release counts next to the picker, instead of a separate stats panel.
  • Clone and download live in a "Code" menu instead of an input row on the root.

Screenshots

Repository home (Gogs itself)

Repository home

File icons

File icons

File icons, dark

File icons, dark

README with the theme-specific SVG logo

README

README, dark

README, dark

A directory with JS, TS, JSON and Markdown

Directory icons

Code menu

Code menu

File with selected lines, dark

File with selected lines, dark

File at a commit (no permalink, editing disabled)

File at a commit

Markdown, Preview

Markdown preview

Markdown, Code

Markdown code

Markdown, Code, dark

Markdown code, dark

Notebook, Code

Notebook code

Notebook

Notebook

PDF

PDF

Org mode

Org mode

Submodule

Submodule

Tag

Tag

Image

Image

Empty repository

Empty repository

Home, dark

Home, dark

Home, 375px
Home, 375px
Markdown, 375px
Markdown, 375px
File, 375px
File, 375px
Directory, 375px
Directory, 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/git/ ./internal/route/... passes, and TestRequireViewAccess 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 and owns the fork bob/widgets. carol has no access. widgets has Markdown, Org mode, a notebook, a PNG, a PDF, a binary, a symlink and a submodule.
  3. API: the root, master/src/server/long.go (with its .editorconfig tab width), a tag and a commit SHA return the right entries and files. A missing ref or path gets 404, and so does ..%2F traversal. carol gets 404 on secret, and alice gets the quick guide on empty. Signed out, editor is no_write and there is no compare target. bob's fork compares against alice/widgets master...bob:master. /alice/widgets?go-get=1 still answers with the go-import meta tag.
  4. Browser, at 1280, dark and 375: browsed directories and files through the list and the breadcrumb, switched branch and tag in the picker, opened the Code menu, selected lines by click and drag and reopened a #L120-L124 link, opened each file kind, and followed Edit into the editor. The wiki's clone box still works. No sideways scroll at 375.
  5. Rebased on main after web: migrate the commit compare page to React #8534 and rechecked with a -tags prod build. alice/alpha got a README with a relative image, a notebook, an Org file, a PNG, a binary, a nested docs/guides/deep and the tag v1.0.0. The home, the Code menu (both archives 200), the nested breadcrumb, the tag picker and switching to long-history (path kept) all work. Clicking a line number writes #L10, and opening #L121-L123 scrolls there and highlights 3 lines, also in a fresh browser. The notebook shows its output, the image shows inline, the binary offers "View raw", and a missing path shows the not-found page (API 404). A new private repository gets 404 from the API and raw for signed out and bob, and 200 for alice. On a new empty repository, switching the clone box between HTTP and SSH now switches both git remote add commands, and the choice survives a reload. Signed out, the empty repository shows the read-only message. scrollWidth is 375 on the home, a directory and a file.
  6. Gogs itself: imported main into alice/gogs. Its README shows the light logo in light mode and the dark logo in dark mode, with the badges. /raw/main/docs/images/logo-light.svg is image/svg+xml with the sandbox CSP, README.md stays text/plain, and an SVG with a <script> opened from /raw/ does not run it. The root says "1 Branch", "0 Releases" and "1 Commit". Files get Pierre's icons (Markdown, Git, Go, JSON, JS, TS, HTML), symlinks keep theirs, and the file header uses the same icon. On long.go#L121-L123 in dark mode, measured contrast on the selected lines is 5.84:1 for punctuation (2.33:1 before), 4.61:1 for function names (3.93:1 before) and 8.1:1 for strings. Light mode is unchanged.
  7. Preview and Code: on README.md, Preview is pressed by default. Code switches to ?plain=true with the highlighted source, Back returns to the preview, and opening ?plain=1#L20-L22 shows the source with lines 20 to 22 selected. The notebook and the Org file get the same buttons, and long.go gets none. The header fits at 375px.

unknwon added a commit that referenced this pull request Nov 13, 2026
@unknwon unknwon mentioned this pull request Nov 13, 2026
3 of 4 tasks
@unknwon
unknwon added this pull request to stack #8457 November 13, 2026 13:51
@unknwon
unknwon force-pushed the code-react-flamego branch 4 times, most recently from 770d79c to efbc651 Compare November 14, 2026 07:11
@unknwon
unknwon force-pushed the code-react-flamego branch 2 times, most recently from 2bbe79f to 5d6c503 Compare November 14, 2026 16:03
@unknwon
unknwon force-pushed the code-react-flamego branch 2 times, most recently from 460f8e2 to 8d9ca79 Compare November 14, 2026 17:11
@unknwon
unknwon force-pushed the code-react-flamego branch 2 times, most recently from 2fc7955 to bb530f6 Compare November 14, 2026 19:00
@unknwon
unknwon force-pushed the code-react-flamego branch 2 times, most recently from a45a327 to 6c27ddf Compare November 14, 2026 19:34
@unknwon
unknwon force-pushed the code-react-flamego branch 2 times, most recently from 27a3982 to 9b407b0 Compare November 14, 2026 20:21
@unknwon
unknwon force-pushed the code-react-flamego branch 5 times, most recently from ee8be3a to 939b590 Compare November 14, 2026 23:00
@unknwon
unknwon force-pushed the code-react-flamego branch 2 times, most recently from 4ad1e97 to 9522885 Compare November 15, 2026 13:45
@unknwon
unknwon force-pushed the code-react-flamego branch 4 times, most recently from a5c8d5c to f1caa37 Compare November 15, 2026 22:45
Base automatically changed from compare-react-flamego to main November 16, 2026 12:52
@unknwon
unknwon marked this pull request as ready for review November 16, 2026 12:54
The repository home and the files at a branch, a tag or a commit
(/{owner}/{repo}/src/{ref}/{path}) are now a React page backed by
/api/web/{owner}/{repo}/src. A directory lists its entries with their last
commits and shows its README. A file is highlighted with line numbers that
select lines into the URL, or rendered when it is Markdown, Org mode or a
notebook, and images, videos and PDFs show inline. The root shows the
description, the branch and release counts, and a menu with the clone URL
and the archives. An empty repository shows the quick guide.
The quick guide's remote URL was always SSH, while the server-rendered
page switched it along with the clone URL.
Raw SVG files are served as sandboxed images instead of plain text, so
relative SVG images in Markdown load, and images marked
#gh-light-mode-only or #gh-dark-mode-only show only in that theme.
Files show the same Pierre icons as the diff file tree, counts of one
branch, release or commit are singular, and selected lines in dark mode
keep code above 4.5:1.
Markdown, Org mode and notebooks get Preview and Code buttons like
GitHub, and ?plain=1 opens the highlighted source with line selection.
@unknwon
unknwon merged commit 9a6feef into main Nov 16, 2026
12 checks passed
@unknwon
unknwon deleted the code-react-flamego branch November 16, 2026 17:35
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