mirror of https://github.com/KDE/kasts.git
Doesn't add width to an html img without a width defined
This attempts to fix the issue described here: https://invent.kde.org/plasma-mobile/kasts/-/issues/20 There seemed to be a loop that occurs when setting an img width which causes the view to re-render which causes the window to grow which goes back to setting an img width causing an loop that keeps growing the img width and eventually crashing. There are a few ways to fix this but I believe not setting a width on an img without a width both fixes it and behaves as expected (see context section). I'm not sure if this is a solution Kasts wants to go with but at the very least it adds more details to the issue. ## Reproducing The gist of that issue is that a crash occurs when you visit https://feed.zugfunk-podcast.de/podcastrss.xml, episode 53 and this is reproducible. I was able to get to the bottom of why that particular podcast episode crashes and can be reproduced with the following content ```html <table style=\"width:30rem;\"><tbody><tr><td style=\"width:14rem;\">Some Text On Left </td><td><img src=\"https://invent.kde.org/plasma-mobile/kasts/-/raw/master/icons/128-apps-kasts.png\"></td></tr></tbody></table> ``` *(can repro by setting this string as a QStringLiteral in Entry.cpp, line 64 when the content is first set and then clicking on any episode) ## Context The problem seems to be with `<img`s that don't have a width set. In those cases the code tries to set the image to the width of the component. The problem with this seems to be that this assumes that these images are on their own horizontal line and that they should take the whole width. So to repro (see content I used to repro above as an example): * put an image tag next to some element that takes some width (like a table where there's a left column with some text and a right column in the right) * img tag without a width What ends up happening is that the `img width` gets updated to the size of the component width but because there's another element to the left of it, it will mean that the resulting view is bigger than the component width which causes `onWidthChanged`(`EntryPage.qml::88`) to be triggered and the `adjustedContent` function to be called again where this whole process happens again (img width is updated to component width -> rendered but it's larger than width -> causing onWidthChanged -> adjustedContent runs again -> rinse/repeat). There are other ways to try to solve this but the three I looked at are: 1. After `adjustedContent` is run, it should update the actual `m_content` so that the following runs can work off the last text update (this will mean that the problematic `else` wouldn't be run constantly). * You can do this by setting the content at the end of the function (`setContent(ret);`) 2. Checking for some reasonable width limit (if width > 10000 then width = 10000) 3. Not resizing an image without a width because we're not sure about the intention of the author * in this case these were small icons for social media that shouldn't be scaled up * I think we shouldn't scale any images because of the same reason but the PR is conservative and just stops it in the case of a img without a width For the PR I went with # 3 because the others led to the icons being scaled but it messed up the look of the page. Closes #20
This commit is contained in:
parent
21b9766ffa
commit
58032dd560
|
@ -360,8 +360,6 @@ QString Entry::adjustedContent(int width, int fontSize)
|
||||||
imgTag.replace(match.captured(3), QStringLiteral("width=\"%1\"").arg(width));
|
imgTag.replace(match.captured(3), QStringLiteral("width=\"%1\"").arg(width));
|
||||||
imgTag.replace(QRegularExpression(QStringLiteral("height=\"([0-9]+)(px)?\"")), QString());
|
imgTag.replace(QRegularExpression(QStringLiteral("height=\"([0-9]+)(px)?\"")), QString());
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
imgTag.insert(4, QStringLiteral(" width=\"%1\"").arg(width));
|
|
||||||
}
|
}
|
||||||
ret.replace(match.captured(), imgTag);
|
ret.replace(match.captured(), imgTag);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue