Bug 481007 - kwin tabbox caching issue: use m_qmlContext.trimComponentCache()
Summary: kwin tabbox caching issue: use m_qmlContext.trimComponentCache()
Status: REPORTED
Alias: None
Product: kwin
Classification: Plasma
Component: tabbox (other bugs)
Version First Reported In: 5.93.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords: qt6
Depends on:
Blocks:
 
Reported: 2024-02-07 13:00 UTC by Benjamin Flesch
Modified: 2024-02-09 19:12 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Flesch 2024-02-07 13:00:41 UTC
SUMMARY
***
Background: As a theme developer, I want to create a WindowSwitcher.qml theme. If the WindowSwitcher.qml file has an error, kwin will not load it and show desktop notification. When I fix the error in the QML file and then try again, kwin still loads the cached file BUT the error message kwin gives points to the new file. 

This suggests that the QMLEngine used in kwin tabbox is polluted with the old QML component.

The call to `m_qmlComponent.reset(nullptr)` in [1] is not enough to clear the invalid QML file from the cache. A call to `m_qmlContext.trimComponentCache()` [2] should be added. However, as trimComponentCache() only deletes unused components, we need to reset m_qmlComponent before we can trim the cache. As m_qmlComponent is null after the reset, we need to use m_qmlContext instead, which points to the same QMLEngine.

***

[1] https://invent.kde.org/bf/kwin-fix-tabbox-cache/-/blob/master/src/tabbox/tabboxhandler.cpp#L251
[2] https://doc.qt.io/qt-6/qqmlengine.html#trimComponentCache

Log: PLEASE NOTE that the first error message shows the "erroneous" line properly, but the second kwin error message shows the fixed file (which should compile!), however it still gives an error.

-----8<-----
kwin_wayland[15029]: kwin_tabbox: Component failed to load:  QList(file:///mytheme/contents/windowswitcher/WindowSwitcher.qml:9:1: module "QtGraphicalEffects" is not installed
import QtGraphicalEffects 1.12
^)
kwin_wayland[15029]: kwin_tabbox: ==  "Alt+Tab"  or  "Alt+Shift+Backtab"
kwin_wayland[15029]: kwin_tabbox: Component failed to load:  QList(file:///mytheme/contents/windowswitcher/WindowSwitcher.qml:9:1: module "QtGraphicalEffects" is not installed
// import QtGraphicalEffects 1.12
^)
----->8-----

STEPS TO REPRODUCE
1. create custom plasma lookandfeel theme with a QML file with syntax errors in `contents/windowswitcher/WindowSwitcher.qml` 
2. load the plasma global theme via `plasma-apply-lookandfeel -a $(pwd)`
3. press ALT+TAB to trigger KWIN error message in journalctl
4. change the file to fix the error
5. press ALT+TAB again and see that KWIN has still same error, but the KWIN error message points to the now fixed line in the QML file


OBSERVED RESULT
QML file does not get re-read from filesystem

EXPECTED RESULT
QML file is re-read from filesystem

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Linux 6.7.4-arch1-1
KDE Plasma Version: 5.93.0-1
KDE Frameworks Version: 5.114.0-2
Qt Version: 6.7.0beta2-1
Comment 1 Benjamin Flesch 2024-02-07 13:02:47 UTC
Merge request here: https://invent.kde.org/plasma/kwin/-/merge_requests/5135
Comment 2 Vlad Zahorodnii 2024-02-07 13:17:45 UTC
I can reproduce but it sounds rather like a QQmlEngine bug.
Comment 3 Vlad Zahorodnii 2024-02-07 13:19:28 UTC
FWIW in qt5 it used to work fine. At least overview used to (before switching to qt_add_qml_module) pick up new code after editing it.
Comment 4 fanzhuyifan 2024-02-09 19:12:32 UTC
Would you be able to submit a upstream bug report to Qt? Thanks a bunch!