[Bug]: Dashboard widgets registered via OCA.Dashboard.register() sometimes never mount (spinner forever) – Vue 3 non-deep `callbacks` watcher race

未关闭 适合新手
#66,926 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
javascript
领域
frontend

调研方向

Race 位于 apps/dashboard/src/DashboardApp.vue:非 deep 的 callbacks watcher 在 register(app, callback) 添加 key 时不会触发,因此 rerenderPanels() 只会从 created() 末尾调用。先阅读 watcher、register() 和 rerenderPanels(),然后用限速网络复现,使某个 widget 在 widgets API 响应之后才注册。完成标准是:较晚注册的 widget 仍能挂载,例如调用 rerenderPanels()(在 register() 中)或让 watcher 变为 deep,同时不破坏已经挂载的 panels。

由索引模型根据 Issue 内容生成。

描述

35-feedback
⚠️ This issue respects the following points: ⚠️
  • This is a bug, not a question or a configuration/webserver/proxy issue.
  • This issue is not already reported on Github OR Nextcloud Community Forum (I've searched it).
  • Nextcloud Server is up to date.
  • I agree to follow Nextcloud's Code of Conduct.
Bug description

Dashboard widgets that use the JavaScript OCA.Dashboard.register() API (e.g. Recommended files, also Photos / Teams) sometimes show the loading spinner forever. A reload (F5), or going to Files and back, often fixes it. The server API returns the data every time (/ocs/v2.php/apps/recommendations/api/v1/recommendations/always → 200 with items), so the problem is in the frontend.

Root cause: in apps/dashboard/src/DashboardApp.vue (current master too):

watch: {
	callbacks() {
		this.$nextTick(() => this.rerenderPanels())
	},
},
// ...
register(app, callback) {
	this.callbacks[app] = callback
},

Since the move to Vue 3, a non-deep watcher on an object does not fire when a key is added (only when the whole object is replaced). So register() never triggers rerenderPanels(). The only call left is the one at the end of created(), which runs after GET /ocs/v2.php/apps/dashboard/api/v1/widgets (and the v2 item fetches) finish.

Widgets register in DOMContentLoaded (e.g. recommendations src/dashboard.js). That event only fires after all module scripts on the page and their chunks are loaded and executed (more than 100 chunk requests on our instance). If the widgets API response arrives before DOMContentLoaded, rerenderPanels() has already run. The callback is stored but never called, and the panel stays loading for good. With a warm browser cache, DOMContentLoaded fires earlier and the race is usually won. That is why the bug looks random and a reload "fixes" it. It shows up much more often behind a reverse proxy / tunnel with some latency.

Quick check of the Vue 3 behaviour:

const { reactive, watch } = require('vue') // 3.5.x
const data = reactive({ callbacks: {} })
let fired = 0
watch(() => data.callbacks, () => fired++)
data.callbacks.recommendations = () => {}
setTimeout(() => console.log(fired), 10) // -> 0

Suggested fix (applied locally on the compiled bundle, which fixes it for us):

 register(app, callback) {
 	this.callbacks[app] = callback
+	this.$nextTick(() => this.rerenderPanels())
 },

(or make the watcher deep: true). rerenderPanels() already skips panels that are mounted, so calling it more often is safe.

Steps to reproduce
  1. Enable the Recommendations app and keep "Recommended files" on the dashboard.
  2. Open the dashboard with an empty browser cache, or with extra network latency (DevTools throttling, or a reverse proxy/tunnel in front of Nextcloud).
  3. The "Recommended files" panel sometimes keeps spinning forever. In the network tab, /recommendations/always returns the items, but the widget is never mounted.
Expected behavior

The widget mounts whenever its register() call happens, also when that is after the first rerenderPanels().

Nextcloud Server version

35 (35.0.2)

Operating system

Other (official nextcloud:35.0.2-apache Docker image)

PHP engine version

PHP 8.5

Web server

Apache (supported)

Database engine version

MariaDB

Is this bug present after an update or on a fresh install?

Not sure — first noticed on 35.0.2 (the bug is in the code since the dashboard moved to Vue 3)

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

What user-backends are you using?
  • Default user-backend (database)
Configuration report
Not relevant (frontend race, reproducible from the code above)
List of activated Apps
dashboard 8.0.0, recommendations 8.0.0, photos 8.0.0, circles 35.0.0
Nextcloud Signing status
No errors before the local workaround patch of dist/dashboard-main.mjs
Nextcloud Logs
No server-side errors; all API requests return 200.
Additional info

Affects every widget that uses OCA.Dashboard.register() (recommendations, photos, circles/teams). API v2 widgets are not affected.

主要语言
PHP
星标
37.6k
派生
5.4k
平均合并
1 天 16 小时
30 天内合并 PR
660

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nextcloud/server 的其他 Issue

查看 nextcloud/server 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。