본문으로 건너뛰기
Skillpedia
웹사이트 및 UI (프런트엔드)7.6k · #13175

real-time-sync

하는 일

이 스킬은 어떤 화면이 다른 사람의 변경을 보여 주기 위해 스스로 새로고침해야 하는지, 그리고 공유 업데이트 채널을 안전하게 켜는 방법을 에이전트에게 알려 줍니다. 데이터가 스스로 바뀌는 페이지를 만드는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓사용자가 새로고침하기 전에 다른 사람이 바꾼 내용을 보여 줘야 하는 페이지일 때.
  • ✓백그라운드 작업의 진행 상황이 사용자가 지켜보는 동안 업데이트되어야 할 때.
  • ✓공개 페이지, 설정 페이지 또는 양식 페이지처럼 실시간 업데이트가 필요 없어 꺼 두어야 할 때.

스킬 링크

https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/real-time-sync/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/real-time-sync/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“새 메일이 도착하면 제가 새로고침하지 않아도 받은편지함이 스스로 업데이트되게 해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 스킬은 간단한 규칙을 둡니다. 사용자 없이도 데이터가 바뀔 수 있고 사용자가 그것을 봐야 할 때만 실시간 확인을 켭니다. 그렇지 않으면 페이지는 포커스나 이동 시 새로고침됩니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Real-Time Sync

Decision rule

Opt in only when both are true:

  1. The data can change without the current user acting.
  2. 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

자주 묻는 질문

에이전트의 편집에도 실시간 동기화가 필요한가요?

아니요. 채팅 실행이 에이전트가 변경할 때마다 데이터를 이미 새로고침합니다.

숨겨진 탭에서도 실시간 확인이 실행되나요?

아니요. 숨겨진 탭은 기본적으로 일시 중지됩니다.

보이는 탭은 얼마나 자주 확인하나요?

처음에는 약 1분마다, 그 뒤에는 유휴 상태일 때 더 드물게 확인합니다.

상세 정보

작성자의 원본 설명

Decide whether a page needs external changes before refresh, then use the opt-in shared SSE and polling transport safely.

repo: BuilderIO/agent-native

인기도

GitHub 스타
7.6k
순위
#13175
라이선스
MIT
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬