Skip to content

add auto-refresh ability based on change streams to document-details#159

Merged
vkarpov15 merged 5 commits intomainfrom
vkarpov15/express-change-streams
Jan 31, 2026
Merged

add auto-refresh ability based on change streams to document-details#159
vkarpov15 merged 5 commits intomainfrom
vkarpov15/express-change-streams

Conversation

@vkarpov15
Copy link
Member

No description provided.

Copilot AI review requested due to automatic review settings January 31, 2026 20:47
@vercel
Copy link

vercel bot commented Jan 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studio Ready Ready Preview, Comment Jan 31, 2026 9:22pm

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, track lastUpdatedAt, and introduce an auto-refresh loop driven by Model.streamDocumentChanges.
  • Extends the frontend API client to support Model.streamDocumentChanges in 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.streamDocumentChanges action, 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.

Comment on lines +169 to +177
async runAutoRefreshLoop() {
if (this.autoRefreshLoopRunning) {
return;
}
this.autoRefreshLoopRunning = true;
this.autoRefreshAbortController = new AbortController();
let retryDelay = 1500;

while (this.autoRefreshEnabled && !this.autoRefreshAbortController.signal.aborted) {
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@vkarpov15 vkarpov15 merged commit 97e52de into main Jan 31, 2026
30 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/express-change-streams branch January 31, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants