Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Apr 26, 2022

Conversation

wxiaoguang
Copy link
Contributor

Fix two UI bugs:

  1. The JS error in imagediff.js, caused by invalid svg. Replace deprecated rootElement with documentElement.
  2. 500 error in diff/compare.tmpl, the $.Context was lost.

Close #19414 (JS error in imagediff.js)

Screenshot after this fix:

image

@wxiaoguang wxiaoguang added this to the 1.17.0 milestone Apr 25, 2022
@wxiaoguang wxiaoguang added topic/ui Change the appearance of the Gitea UI type/bug labels Apr 25, 2022
@wxiaoguang wxiaoguang changed the title Fix two UI bugs: JS error in imagediff, 500 error in diff/compare.tmpl Fix two UI bugs: JS error in imagediff.js, 500 error in diff/compare.tmpl Apr 25, 2022
@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Apr 25, 2022
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 25, 2022
@wxiaoguang wxiaoguang merged commit fef26c1 into go-gitea:main Apr 26, 2022
@wxiaoguang wxiaoguang deleted the fix-ui-bug branch April 26, 2022 03:14
const width = svg?.width?.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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SVG without width/height is not invalid. The attributes default to auto which essentially means 100% to fill the parent container:

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/width#svg

Not sure whether we should actually fill the container or default them to something more sane like 400px maybe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's your suggestion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I'd render with a max-width/max-height somewhere between 40% and 50% container width and render those size-less SVGs with that size as well. Maybe it can be done in CSS only, but JS-based solutions are also an option.

Copy link
Member

@silverwind silverwind Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another simpler option may be to default to 300px width / 150px height as defined in the SVG spec here for rendering in CSS contexts:

https://svgwg.org/specs/integration/#svg-css-sizing

If any of the sizing attributes are missing, resolve the missing ‘svg’ element width to '300px' and missing height to '150px' (using CSS 2.1 replaced elements size calculation).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you help to propose a PR about the refactoring?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can check what can be done, but it would be helpful to have a proper testing repo. https://try.gitea.io/wxiaoguang/test/pulls/6/files seems unsuitable as is has a namespace-less SVG which will never properly render.

Copy link
Contributor Author

@wxiaoguang wxiaoguang Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But https://try.gitea.io/wxiaoguang/test/pulls/6/files is why the bug occurs ..... end users made the mistakes. This PR just make UI more friendly to end users if they made mistakes.

What do you mean by suitable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suiteable in the sense that it renders something, e.g. with namespace and some visible shape data.

Copy link
Contributor Author

@wxiaoguang wxiaoguang Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can not understand why you need that .... the purpose of this PR is to handle invalid SVG gracefully.

If you work on a correct SVG, it's not related to this problem directly.

If you need some work for some special SVG, you can just prepare it .......... it would not be too difficult to construct a SVG manually by typing <svg> ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course I can/will create test files myself.

@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/ui Change the appearance of the Gitea UI type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JS error in imagediff.js
5 participants