add auto-refresh ability based on change streams to document-details#159
add auto-refresh ability based on change streams to document-details#159
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Pull request overview
This PR adds a change-stream–driven auto-refresh mechanism for the document details view, along with frontend controls and backend streaming support.
Changes:
- Refactors the document page to centralize fetching in
refreshDocument, tracklastUpdatedAt, and introduce an auto-refresh loop driven byModel.streamDocumentChanges. - Extends the frontend API client to support
Model.streamDocumentChangesin both lambda (polling stub) and non-lambda (SSE) environments, and wires new manual/auto-refresh controls into the document UI. - Updates the backend to optionally open a MongoDB change stream, exposes a new
Model.streamDocumentChangesaction, and authorizes it for read-capable roles.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/document/document.js | Adds document refresh helper, auto-refresh state machine, and change-stream integration for the document view. |
| frontend/src/document/document.html | Updates toolbar to show last loaded time and adds manual refresh / auto-refresh controls for desktop and mobile. |
| frontend/src/api.js | Introduces Model.streamDocumentChanges generators for lambda (polling) and non-lambda (SSE) environments. |
| express.js | Ensures an options object with changeStream defaulting to true is passed into the backend for Express deployments. |
| backend/index.js | Creates an optional shared MongoDB changeStream via db.watch() and passes it into the actions layer. |
| backend/authorize.js | Authorizes the new Model.streamDocumentChanges action for owner/admin/member/readonly roles. |
| backend/actions/Model/streamDocumentChanges.js | Implements a generator-based action that multiplexes a shared change stream and yields events for a single document. |
| backend/actions/Model/index.js | Exports the new streamDocumentChanges action from the Model action bundle. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| async runAutoRefreshLoop() { | ||
| if (this.autoRefreshLoopRunning) { | ||
| return; | ||
| } | ||
| this.autoRefreshLoopRunning = true; | ||
| this.autoRefreshAbortController = new AbortController(); | ||
| let retryDelay = 1500; | ||
|
|
||
| while (this.autoRefreshEnabled && !this.autoRefreshAbortController.signal.aborted) { |
There was a problem hiding this comment.
runAutoRefreshLoop assumes this.autoRefreshAbortController is always non-null while the loop is running, but stopAutoRefresh() sets it to null while the loop may still be executing. This means the while (this.autoRefreshEnabled && !this.autoRefreshAbortController.signal.aborted) condition (and the similar check in the catch block) can throw a runtime error if stopAutoRefresh() is called during an in-flight iteration. To avoid this race, keep a local reference to the AbortController inside runAutoRefreshLoop (and use that for signal checks) or ensure all signal access is guarded against null and that stopAutoRefresh() doesn’t clear the controller until the loop has fully exited.
No description provided.