Skip to content

Bust plugin component URLs on hot-reload - #10576

Closed
fresh3nough wants to merge 1 commit into
omacom:quattrofrom
fresh3nough:fix/10568-plugin-reload-cache-bust
Closed

fresh3nough wants to merge 1 commit into
omacom:quattrofrom
fresh3nough:fix/10568-plugin-reload-cache-bust

Conversation

@fresh3nough

Copy link
Copy Markdown
Contributor

Summary

Fixes #10568.

finishPluginReload guarded plugin hot-reload with:

if (typeof Qt.clearComponentCache === "function") Qt.clearComponentCache()

clearComponentCache is a QQmlEngine C++ method and is not on the QML Qt object, so typeof is always "undefined", the call never runs, and rescan() re-instantiates the previous compiled component. Plugin file edits looked like no-ops.

Change

  1. PluginRegistry.componentCacheEpoch — advanced on each hot-reload.
  2. entryPointUrl appends ?omarchyReload=<epoch> when the epoch is non-zero so Loader / createComponent URLs change and QML is re-read from disk.
  3. finishPluginReload always bumps the epoch before rescan(), still calls Qt.clearComponentCache if a future Qt/Quickshell exposes it, and logs a one-shot WARN naming omarchy restart shell as fallback.
  4. Docs: rescanPlugins note about cache-bust + restart fallback.

Evidence

Bug reproduced

$ QT_QPA_PLATFORM=offscreen qml6 /tmp/probe.qml ; echo exit=$?
# typeof Qt.clearComponentCache !== "function"
exit=3

Pre-fix finishPluginReload only cleared the cache inside that always-false guard.

Fix validated

bash test/shell.d/plugin-reload-cache-test.sh
ok - PluginRegistry cache-busts entryPointUrl on reload epoch
ok - finishPluginReload advances epoch and warns when cache clear is missing
ok - Qt.clearComponentCache remains unavailable on QML Qt object
ok - plugin-registry fixture asserts entryPointUrl epoch cache-bust

bash test/shell.d/plugin-registry-contract-test.sh
ok - plugin registry contract checks pass

Test plan

  • qml6 probe: clearComponentCache still absent on QML Qt
  • plugin-reload-cache-test.sh
  • plugin-registry-contract-test.sh (entryPointUrl epoch assertion)
  • Manual: edit a local plugin QML, trigger reload / save, confirm new behaviour without full shell restart

Qt.clearComponentCache is a QQmlEngine C++ method and is never exposed on
the QML Qt object, so the guard in finishPluginReload was always false
and rescan reused stale compiled components after plugin file edits.

Advance a componentCacheEpoch before each rescan and append it as an
omarchyReload query on entryPointUrl so Loaders re-read disk. Warn once
when the C++ clear API is missing, and document restart-shell as the
fallback if a reload still looks stale.

Fixes #10568

Signed-off-by: fresh3nough <anonwurcod@proton.me>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at eac7c4f. The diagnosis is right: Qt.clearComponentCache is not on the QML Qt object, so the guard in finishPluginReload never fires and a rescan reuses the compiled component. But this fix only partly covers the problem, and #11408 fixes the same bug more completely, so I'm recommending that one to the maintainer instead.

What I checked, by reading only. Nothing was run on a worker, because a fix that isn't the recommended one isn't worth a worker:

  • Only the entry file is refreshed. ?omarchyReload=<epoch> changes the entry point's URL (shell/services/PluginRegistry.qml:111). Types the entry file pulls in from its own directory, such as a sibling Helper.qml, still resolve through the implicit directory import. That import is keyed by the directory, which the query string does not change, so those types are served from the cache as before. The repro posted on Plugin hot-reload never clears the component cache: the Qt.clearComponentCache guard is always false #10568 shows exactly this: the entry file updates, its helper stays stale, and newly added files fail to load. Most plugins are more than one file, so most edits would still look like no-ops.
  • Every reload invalidates every plugin. The epoch is global (shell/shell.qml:790), so any watcher event recompiles every plugin's entry point, unrelated ones included. Each recompile also leaves another component cached under a new URL.
  • The tests don't exercise a reload. plugin-reload-cache-test.sh greps the source and asserts that the Qt runtime still lacks the API. The fixture only checks that the URL string changes. None of them edits a loaded component and checks that the new code runs.

#11408 handles a local .qml change by calling Quickshell.reload(false). That builds a new engine, which throws away every cache this PR can't reach. Its cost is a soft reload of the whole shell. It has gaps of its own: the rescanPlugins IPC still only rescans, and .js/qmldir edits aren't treated as code changes. Those will be raised on its own review. Two fixes for one bug would conflict, so the choice between them is the maintainer's.

Second opinion: Codex Medium compared the two PRs without being told my conclusion. It also preferred #11408, and it independently reached the directory-import explanation above, though its independence from this session isn't guaranteed.

Waiting on the maintainer to choose between this PR and #11408.

@omarchybot

Copy link
Copy Markdown
Collaborator

Looked at this again at eac7c4f, because the review of #13911 handed that PR's runtime test over to be folded in here. I haven't pushed it to this branch. It would only belong here if this were the fix being recommended, and it still isn't.

The reason hasn't changed since the last review. entryPointUrl (shell/services/PluginRegistry.qml:111) gives only the entry file a new URL. Anything the entry file imports, such as a sibling Helper.qml or a Model.js, keeps its old URL and stays cached. #11408 reloads the engine on a local .qml, .js or qmldir change, so it covers those, and it has a runtime test for an imported JS edit. That's a missed case rather than a matter of taste, so it outweighs this PR being the older one. The test from #13911 would pass on this PR's mechanism, but it only edits the entry file, so it can't show the import case working.

I checked this by reading the three diffs against quattro. Nothing was run on a worker. Codex Medium compared the three PRs separately, without my answer. It also recommended #11408 for the same missed case, and found no other defect in this diff. Its independence from this session isn't guaranteed.

Still waiting on the maintainer to choose between this PR and #11408. If they choose this one, folding in the test from #13911 comes first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugin hot-reload never clears the component cache: the Qt.clearComponentCache guard is always false

2 participants