Skip to content

Commit fef26c1

Browse files
wxiaoguang6543
andauthored
Fix two UI bugs: JS error in imagediff.js, 500 error in diff/compare.tmpl
Co-authored-by: 6543 <[email protected]>
1 parent 741c55b commit fef26c1

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

templates/repo/diff/compare.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
<div class="twelve wide column issue-title">
192192
{{.i18n.Tr "repo.pulls.has_pull_request" (Escape $.RepoLink) (Escape $.RepoRelPath) .PullRequest.Index | Safe}}
193193
<h1>
194-
<span id="issue-title">{{RenderIssueTitle .PullRequest.Issue.Title $.RepoLink $.Repository.ComposeMetas}}</span>
194+
<span id="issue-title">{{RenderIssueTitle $.Context .PullRequest.Issue.Title $.RepoLink $.Repository.ComposeMetas}}</span>
195195
<span class="index">#{{.PullRequest.Issue.Index}}</span>
196196
</h1>
197197
</div>

web_src/js/features/imagediff.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ function getDefaultSvgBoundsIfUndefined(svgXml, src) {
44
const DefaultSize = 300;
55
const MaxSize = 99999;
66

7-
const svg = svgXml.rootElement;
8-
9-
const width = svg.width.baseVal;
10-
const height = svg.height.baseVal;
7+
const svg = svgXml.documentElement;
8+
const width = svg?.width?.baseVal;
9+
const height = svg?.height?.baseVal;
10+
if (width === undefined || height === undefined) {
11+
return null; // in case some svg is invalid or doesn't have the width/height
12+
}
1113
if (width.unitType === SVGLength.SVG_LENGTHTYPE_PERCENTAGE || height.unitType === SVGLength.SVG_LENGTHTYPE_PERCENTAGE) {
1214
const img = new Image();
1315
img.src = src;
@@ -29,6 +31,7 @@ function getDefaultSvgBoundsIfUndefined(svgXml, src) {
2931
height: DefaultSize
3032
};
3133
}
34+
return null;
3235
}
3336

3437
export default function initImageDiff() {
@@ -88,6 +91,10 @@ export default function initImageDiff() {
8891
info.$image.on('load', () => {
8992
info.loaded = true;
9093
setReadyIfLoaded();
94+
}).on('error', () => {
95+
info.loaded = true;
96+
setReadyIfLoaded();
97+
info.$boundsInfo.text('(image error)');
9198
});
9299
info.$image.attr('src', info.path);
93100

0 commit comments

Comments
 (0)