real-time-sync
Skill này làm gì
Skill này cho biết khi nào một màn hình nên tự làm mới vì thay đổi do người khác thực hiện, và cách bật kênh cập nhật chung một cách an toàn. Skill dành cho lập trình viên xây trang có dữ liệu tự thay đổi.
Khi nào nên dùng
- ✓Khi một trang phải hiển thị thay đổi của người khác trước khi người dùng tải lại.
- ✓Khi tiến trình của một công việc nền nên cập nhật trong lúc người dùng theo dõi.
- ✓Khi một trang công khai, cài đặt hoặc biểu mẫu không cần cập nhật trực tiếp và nên được tắt.
Liên kết skill
https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/real-time-sync/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Làm cho hộp thư đến tự cập nhật khi có thư mới đến, mà tôi không phải tải lại.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill đặt một quy tắc đơn giản: chỉ bật kiểm tra trực tiếp khi dữ liệu có thể thay đổi mà không cần người dùng và người dùng cần thấy điều đó. Nếu không, trang làm mới khi lấy được focus hoặc khi điều hướng.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Real-Time Sync
Decision rule
Opt in only when both are true:
- The data can change without the current user acting.
- The user needs to see that change before refreshing or navigating.
A local agent edit does not meet this rule. The chat run stream already invalidates action queries and source counters after each side-effecting tool and again at run end, without opening a background poll.
Opt in
- Slides deck editor: another collaborator can edit the open deck.
- Mail inbox: new mail can arrive while the inbox is open.
- A watched job: a background job changes progress while the user watches it.
- Cross-tab state: state must converge across this user's open tabs without a new action.
Keep it off
- Public, anonymous, marketing, docs, and SSR pages.
- Settings, forms, and read-mostly lists or dashboards. Refresh them on focus or navigation instead.
- Single-user agent edits. The chat run stream handles those.
- Pages where an update is useful eventually but not before the next refresh.
Cost and behavior
useDbSync() has no background transport unless the page opts in with a
non-empty reason. One transport is shared per tab. A visible opted-in tab polls
at 1 minute, then 2, then 5 minutes while idle; user activity or a local
mutation resets that sequence. Hidden tabs pause by default. During an active
agent run, opted-in sync can poll at its configured interval; local tool
completion and run-end invalidation do not depend on that poll.
On a long-lived host, same-process changes stream over
/_agent-native/events; polling is the cross-process fallback. On a production
serverless host, the local events endpoint refuses the long-lived stream and
/_agent-native/poll carries remote changes. The paid Hosted Realtime Sync
Gateway is not required for this pattern.
While a collab doc shows another person present, the transport polls every
2.5 s instead (acquireCollabPollBoost(), held by the collab client, not by
pages). It is a no-op whenever a stream is connected, lapses after 3 minutes
without input or remote events, and never applies to lone tabs.
Use the hook
Declare the reason beside the route gate so reviewers can see why the page pays for remote sync:
useDbSync({
queryClient,
realtime: isPrivateDeckEditorPath(location.pathname)
? { reason: "other collaborators can edit this deck while it is open" }
: undefined,
pauseWhenHidden: true,
});
The reason is required by the TypeScript API. Opt in only for a named private or authenticated route; public, documentation, and SSR pages should not start a background transport.
An opted-in page only hears about an action when its change event reaches the
current user. By default an action event reaches the actor alone, so a
collaborator's comment, save, or agent edit never arrives. Declare
changeResource: (input, result) => ({ resourceType, resourceId }) on the
mutating action and the event also reaches everyone who can read that resource.
Name it from input when the call carries the resource id (Content's
documentChangeResource, Slides' comment actions) and from result when the
call is keyed by a child id (Design's designChangeResource for
delete-file); return null for a call that changed nothing. Do not publish a
parallel per-template event for the same purpose.
Do not start subscribeSyncEvents() or an EventSource in a feature to bypass
the decision. subscribeSyncEvents() is a lower-level transport subscription
used by the existing Yjs collaboration client and narrow framework plumbing.
Keep Yjs collaborative editing on its existing channel.
Query freshness
Prefer useActionQuery() for action-backed data. Mutating actions refresh local
action observers; the chat run stream also invalidates them for agent tool
side effects. Raw queries should include the relevant source counters:
const versions = useChangeVersions(["dashboards", "action"]);
useQuery({
queryKey: ["dashboard", id, versions],
queryFn: () => fetchDashboard(id),
placeholderData: (previous) => previous,
});
That covers local chat-run edits. Remote edits reach the counter through
useDbSync() only on an opted-in page. Use useReconciledState when a form or
inline editor copies a query value into local state so incoming data does not
replace active typing.
URL commands (__set_url__, set-url, and set-search-params) and
refresh-screen also flow through local chat events. The sideb
Câu hỏi thường gặp
Thay đổi của agent có cần đồng bộ trực tiếp không?
Không. Lần chạy chat đã làm mới dữ liệu sau mỗi thay đổi của agent.
Kiểm tra trực tiếp có chạy trong tab ẩn không?
Không. Các tab ẩn tạm dừng theo mặc định.
Một tab đang hiển thị kiểm tra bao lâu một lần?
Ban đầu khoảng mỗi phút, rồi thưa hơn khi ở trạng thái rảnh.
Chi tiết
Mô tả gốc của tác giả
Decide whether a page needs external changes before refresh, then use the opt-in shared SSE and polling transport safely.
repo: BuilderIO/agent-native
Độ phổ biến
- Sao GitHub
- 7.6k
- Vị trí xếp hạng
- #13175
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
design-exploration
7.6kGiúp agent của bạn khám phá nhiều hướng thiết kế giao diện song song, để bạn chọn một hướng rồi tinh chỉnh thiết kế đã chọn.
visual-edit
7.6kGiúp agent của bạn mở một ứng dụng cục bộ đang chạy trong trình chỉnh sửa trực quan, để bạn xem và sửa các màn hình thật cùng nhau.
turn-into-app
7.6kBiến quy trình, bảng tính hoặc dự án thành ứng dụng trực quan có màn hình đầy đủ dữ liệu, với agent làm việc phía sau các điều khiển.
visual-plan
7.6kBiến một kế hoạch viết bằng văn bản thuần thành kế hoạch trực quan tương tác, có sơ đồ, bản đồ file, đoạn code và các câu hỏi còn mở.
Skill tương tự
angular-developer
280kGiúp agent của bạn viết code Angular và tư vấn cấu trúc dự án, hữu ích khi bắt đầu dự án mới hoặc cải thiện hiệu suất.
frontend-a11y
280kGiúp agent của bạn làm cho giao diện web dễ tiếp cận với mọi người. Đảm bảo website và ứng dụng hoạt động tốt với trình đọc màn hình và điều hướng bằng bàn phím.
frontend-patterns
280kGiúp agent của bạn áp dụng các mẫu hiện đại trong phát triển frontend. Tối ưu hiệu năng, quản lý trạng thái và tuân theo thực hành tốt nhất với React và Next.js.