Fix two UI bugs: JS error in imagediff.js, 500 error in diff/compare.tmpl

Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
wxiaoguang 2022-04-26 11:14:01 +08:00 committed by GitHub
parent 741c55b4ea
commit fef26c159c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View file

@ -191,7 +191,7 @@
<div class="twelve wide column issue-title"> <div class="twelve wide column issue-title">
{{.i18n.Tr "repo.pulls.has_pull_request" (Escape $.RepoLink) (Escape $.RepoRelPath) .PullRequest.Index | Safe}} {{.i18n.Tr "repo.pulls.has_pull_request" (Escape $.RepoLink) (Escape $.RepoRelPath) .PullRequest.Index | Safe}}
<h1> <h1>
<span id="issue-title">{{RenderIssueTitle .PullRequest.Issue.Title $.RepoLink $.Repository.ComposeMetas}}</span> <span id="issue-title">{{RenderIssueTitle $.Context .PullRequest.Issue.Title $.RepoLink $.Repository.ComposeMetas}}</span>
<span class="index">#{{.PullRequest.Issue.Index}}</span> <span class="index">#{{.PullRequest.Issue.Index}}</span>
</h1> </h1>
</div> </div>

View file

@ -4,10 +4,12 @@ function getDefaultSvgBoundsIfUndefined(svgXml, src) {
const DefaultSize = 300; const DefaultSize = 300;
const MaxSize = 99999; const MaxSize = 99999;
const svg = svgXml.rootElement; const svg = svgXml.documentElement;
const width = svg?.width?.baseVal;
const width = svg.width.baseVal; const height = svg?.height?.baseVal;
const height = svg.height.baseVal; if (width === undefined || height === undefined) {
return null; // in case some svg is invalid or doesn't have the width/height
}
if (width.unitType === SVGLength.SVG_LENGTHTYPE_PERCENTAGE || height.unitType === SVGLength.SVG_LENGTHTYPE_PERCENTAGE) { if (width.unitType === SVGLength.SVG_LENGTHTYPE_PERCENTAGE || height.unitType === SVGLength.SVG_LENGTHTYPE_PERCENTAGE) {
const img = new Image(); const img = new Image();
img.src = src; img.src = src;
@ -29,6 +31,7 @@ function getDefaultSvgBoundsIfUndefined(svgXml, src) {
height: DefaultSize height: DefaultSize
}; };
} }
return null;
} }
export default function initImageDiff() { export default function initImageDiff() {
@ -88,6 +91,10 @@ export default function initImageDiff() {
info.$image.on('load', () => { info.$image.on('load', () => {
info.loaded = true; info.loaded = true;
setReadyIfLoaded(); setReadyIfLoaded();
}).on('error', () => {
info.loaded = true;
setReadyIfLoaded();
info.$boundsInfo.text('(image error)');
}); });
info.$image.attr('src', info.path); info.$image.attr('src', info.path);