Fix duplicate script declaration error in pull request merge box#36759
Fix duplicate script declaration error in pull request merge box#36759silverwind wants to merge 30 commits intogo-gitea:mainfrom
Conversation
Replace the inline <script> in the merge box template with a JSON data attribute. The previous approach used executeScripts() to re-append <script> tags to document.body on each merge box reload, but never removed old ones, causing "Identifier has already been declared" errors on the second reload. The merge form data is now passed via a data-merge-form attribute using dict/JsonUtils.EncodeToString, and read by JS via JSON.parse. This eliminates the need for executeScripts() entirely. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The |
The closing </div> is matched with an opening <div> inside an {{else}}
branch, which djlint's regex parser cannot trace through Go template
conditionals, causing a spurious "orphan tag" warning.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…Data Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Or you can use for a "quick" fix. |
|
No, I'm of the opionion all script tags must go, to allow running without |
* origin/main: Move Fomantic dropdown CSS to custom module (go-gitea#36530) Use "Enable Gravatar" but not "Disable" (go-gitea#36771) feat: add branch_count to repository API (go-gitea#35351) (go-gitea#36743) Deprecate RenderWithErr (go-gitea#36769) Lazy-load some Vue components, fix heatmap chunk loading on every page (go-gitea#36719) Filter out untracked files from spellchecking (go-gitea#36756) Fix CSS stacking context issue in actions log (go-gitea#36749) Fix milestone/project text overflow in issue sidebar (go-gitea#36741) Update tool dependencies and fix new lint issues (go-gitea#36702) Instance-wide (global) info banner and maintenance mode (go-gitea#36571) Add created_by filter to SearchIssues (go-gitea#36670) Inline and lazy-load EasyMDE CSS, fix border colors (go-gitea#36714) # Conflicts: # templates/repo/issue/view_content/pull_merge_box.tmpl # web_src/js/features/repo-issue-pull.ts
Move the ~70-line `JsonUtils.EncodeToString(dict ...)` template logic for the pull request merge form into a Go struct with `json.Marshal`, improving IDE support, type safety, and compile-time error checking. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: silverwind <me@silverwind.io>
wxiaoguang
left a comment
There was a problem hiding this comment.
No. don't do ctx.Data["RequireSigned"].(bool)
|
AI code is full of bad smells. Please make sure the code is maintainable. It's even worse than before, and doesn't match the expectation:
All dynamic key access, no strict syntax, no compiler time error check, harder to read/test/refactor |
Pass blocked-by values and other locals via mergeFormParams struct instead of re-reading from ctx.Data or making duplicate DB calls. Remove unused SliceUtils.Pack and djlint H025 exclude. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Better now? |
If you can understand the logic 2 months later, then it is better. To me, it's just better than the worst. |
|
IDK, this is replacing a compact-ish json with almost 3 times as much go code. I would go back to template logic. |
Because you duplicated the logic in go again. To correctly refactor, the logic in templates (e.g.: canMergeNow) should be done in backend. |
|
Should be good now, I added e2e tests for the merge box as well. |
Consolidate 7 separate tests into 3 by sharing repo setup across related assertions. Reduces test time from ~32s to ~13s by avoiding redundant repo/branch/PR creation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes the duplicate script declaration issue in the PR merge box by removing inline <script> data injection and shifting merge-form data construction to Go, passing it to the Vue merge form via a data-merge-form JSON attribute.
Changes:
- Replace merge-form inline
<script>+executeScripts()re-execution withdata-merge-formJSON on the Vue mount element. - Add Go-side merge-form JSON builder (
pull_merge_form.go) and precomputeAllOverridableChecksOk/CanMergeNowin Go. - Add Playwright e2e coverage for merge box UI behavior (style switching, status checks, auto-merge, merge completion) and supporting API helpers.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| web_src/js/features/repo-issue-pull.ts | Mount merge form with root-prop and remove dynamic script re-execution on merge-box reload. |
| web_src/js/components/PullRequestMergeForm.vue | Read merge-form data from data-merge-form on the mount element instead of window.config.pageData. |
| templates/repo/issue/view_content/pull_merge_box.tmpl | Render Vue mount point with data-merge-form and use server-computed mergeability flags. |
| routers/web/repo/pull_merge_form.go | New Go builder for merge-form JSON and mergeability flag computation. |
| routers/web/repo/pull.go | Return structured merge inputs from PR view prep to feed merge-form JSON builder. |
| routers/web/repo/issue_view.go | Centralize PR review/merge preparation and wire merge-form JSON builder into the view pipeline. |
| tests/e2e/utils.ts | Add API helpers for branch creation, PR creation, commit statuses, and branch protections. |
| tests/e2e/repo/pull-merge-box.test.ts | New e2e tests validating merge box rendering and behavior across key states. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Rename GetCommitMessages to SquashCommitMessages since it holds a string value, not a getter. Rename DefaultMergeMessage to DefaultMergeBody in the JSON struct and Vue component to avoid confusion with the mergeFormParams.DefaultMergeMessage field which holds the commit title. Co-Authored-By: Claude claude-opus-4-6 20250627 <noreply@anthropic.com>
* origin/main: (27 commits) Fix OAuth2 authorization code expiry and reuse handling (go-gitea#36797) Fix org permission API visibility checks for hidden members and private orgs (go-gitea#36798) Fix non-admins unable to automerge PRs from forks (go-gitea#36833) upgrade to github.com/cloudflare/circl 1.6.3, svgo 4.0.1, markdownlint-cli 0.48.0 (go-gitea#36837) Fix dump release asset bug (go-gitea#36799) build(deps): update material-icon-theme v5.32.0 (go-gitea#36832) Fix bug to check whether user can update pull request branch or rebase branch (go-gitea#36465) Fix forwarded proto handling for public URL detection (go-gitea#36810) Fix artifacts v4 backend upload problems (go-gitea#36805) Add a git grep search timeout (go-gitea#36809) fix(repo): unify DEFAULT_SHOW_FULL_NAME output in templates and dropdown (go-gitea#36597) Harden render iframe open-link handling (go-gitea#36811) [skip ci] Updated translations via Crowdin fix: /repos/{owner}/{repo}/actions/{runs,jobs} requiring owner permissions (go-gitea#36818) Fix CRAN package version validation to allow more than 4 version components (go-gitea#36813) Fix API not persisting pull request unit config when has_pull_requests is not set (go-gitea#36718) feat: Add Actions API rerun endpoints for runs and jobs (go-gitea#36768) Fix bug when pushing mirror with wiki (go-gitea#36795) Pull Request Pusher should be the author of the merge (go-gitea#36581) Delete non-exist branch should return 404 (go-gitea#36694) ... # Conflicts: # routers/web/repo/issue_view.go
| } | ||
| preparePullViewPullInfo(ctx, issue) | ||
| preparePullViewReviewAndMerge(ctx, issue) | ||
| preparePullViewReviewAndMergeAll(ctx, issue) |
There was a problem hiding this comment.
if ctx.Written() {
return
}missed here?
Resolve conflicts in: - tests/e2e/utils.ts: keep both branch's new API helpers and main's user/password helpers - web_src/js/components/PullRequestMergeForm.vue: use pageData instead of DOM attribute - web_src/js/features/repo-issue-pull.ts: use simplified import without props Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
wxiaoguang
left a comment
There was a problem hiding this comment.
According to the recent experiences of PR reviewing, I don't trust the AI code here, it just looks like a new pile of slop.
Two real examples of AI slop:
They both: look good, seem running well for some cases, contain superficial tests. But the AI's solutions are completely wrong and make the situation worse.

Move merge form JSON construction from template to Go, and clean up the data flow.
<script>withdata-merge-formJSON attribute on the Vue mount pointJsonUtils.EncodeToStringlogic into typed Go structs withjson.Marshal(pull_merge_form.go)allOverridableChecksOkandcanMergeNowin Go, eliminating duplicate template logicFixes: #36759
🤖 Generated with Claude Code