Skip to content

refactor(vue,svelte): share the isBrowser guard - #322

Closed
prisis wants to merge 4 commits into
alphafrom
fix/framework-adapter-upload-guards
Closed

prisis wants to merge 4 commits into
alphafrom
fix/framework-adapter-upload-guards

Conversation

@prisis

@prisis prisis commented Aug 2, 2026

Copy link
Copy Markdown
Member

Work from an agent worktree, pushed under a descriptive name (local branch was worktree-agent-a5593d536c42bc6b6).
Branched before #288/#289 landed, so it needs a rebase onto current alpha before merge.

Commits

  • refactor(vue,svelte): share the isBrowser guard
  • fix(vue,svelte): guard eager subscriptions and timers against SSR
  • fix(angular,svelte): key pagination pages with stableWireKey
  • fix(angular): reset upload signals on restart and guard pause/resume

prisis added 4 commits August 1, 2026 19:13
Extract the repeated `(globalThis as { window?: unknown }).window !==
undefined` expression into a single `shared/is-browser.ts` helper and
point the three existing SSR guards at it, so the next adapter reaches
for one canonical check instead of a byte-similar inline copy.
Vue's useQuery/subscribeToQuery/use-paginated-core and Svelte's agent()/
rateLimit() open live subscriptions (and, for rateLimit, a setInterval)
eagerly with no browser check. A component's setup/init can run inside
renderToString with no window and no unmount hook, so each server
render leaked a subscription (or a timer) for the life of the process.

Guard each subscription-opening/timer-arming call with the shared
isBrowser() helper, mirroring the existing use-presence.ts/agent-chat.ts
pattern: browser behaviour is unchanged, SSR leaves refs/stores at their
inert initial values with a callable no-op teardown.

Composables built on the guarded primitives (useAgent, useAgentChat,
useAgentState, useAgentToolEvents) inherit the fix transitively; their
test suites now stub `window` per test (vitest's env is `node`, so none
is present by default) to keep asserting real browser behaviour, with a
dedicated SSR test added per guarded primitive to prove the guard.

Solid (createEffect/onMount) and Angular (shouldOpenSubscription/
PLATFORM_ID) are untouched — already SSR-safe by construction.
Both adapters built their per-page subscription key with raw
JSON.stringify, unlike Vue/Solid/the client SDK's SubscriptionRegistry,
which already converged on stableWireKey. A wire-typed page arg
(bigint, Date, bytes) throws instead of tokenizing deterministically,
and a page-key computed from an unsorted arg record can drift from the
canonical form used everywhere else.

Both engines hold their base args as a fixed reference for the whole
instance lifetime, so a within-engine key-order drift is not reachable
today; the duplicate-subscription/result-carry-miss risk described in
the audit lives at the client SDK's dedup layer (already correct), not
in this adapter's own bookkeeping — recorded in the new tests' comments
rather than asserted, since there is no reachable pre/post-fix
difference to demonstrate for that scenario. The wire-typed-arg case is
directly demonstrable and covered.
`upload()` documents `start` as "start (or restart)" but never reset
its signals: a retry after a failed upload rendered status "uploading"
alongside the previous failure's `error`, and a subsequent success left
`error` stale next to `status: "success"`. `pause()`/`resume()` were
also unconditional, so calling either outside an in-flight upload
stamped "paused"/"uploading" over a terminal state.

`start` now clears `error`/`result`/`progress`/`isPaused` and stamps
`status: "uploading"` synchronously before delegating to the adapter.
`pause()`/`resume()` are no-ops unless the handle is actually
`"uploading"`/`"paused"`. Updated the one existing test that paused
from `"idle"` (which encoded the bug) to drive the adapter's start
callback first.
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@prisis, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 64cb4944-9df2-4b8b-8a61-410b39ad6de7

📥 Commits

Reviewing files that changed from the base of the PR and between 6a4dd72 and 0c8ced8.

⛔ Files ignored due to path filters (13)
  • packages/angular/__tests__/paginated-query.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/angular/__tests__/upload.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/svelte/__tests__/agent.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/svelte/__tests__/paginated-query.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/svelte/__tests__/rate-limit.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/vue/__tests__/hydrate-preloaded.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/vue/__tests__/use-agent-chat.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/vue/__tests__/use-agent-state.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/vue/__tests__/use-agent-tool-events.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/vue/__tests__/use-agent.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/vue/__tests__/use-paginated-query.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/vue/__tests__/use-subscription.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • shared/is-browser.ts is excluded by none and included by none
📒 Files selected for processing (11)
  • packages/angular/src/paginated-query.ts
  • packages/angular/src/upload.ts
  • packages/svelte/src/agent-chat.ts
  • packages/svelte/src/agent.ts
  • packages/svelte/src/paginated-query.ts
  • packages/svelte/src/presence.ts
  • packages/svelte/src/rate-limit.ts
  • packages/vue/src/use-paginated-core.ts
  • packages/vue/src/use-presence.ts
  • packages/vue/src/use-query.ts
  • packages/vue/src/use-subscription.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@netlify

netlify Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

❌ Deploy Preview for lunorash failed.

Name Link
🔨 Latest commit 0c8ced8
🔍 Latest deploy log https://app.netlify.com/projects/lunorash/deploys/6a6f0c19a29c920008b3f977

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Thank you for confirming the Contributor License Agreement! 🙏

@prisis

prisis commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

Closing: this PR was opened in error by an automated run, outside the scope of its task.

No work is lost — the branch is retained on origin and this PR can be reopened at any time.

Context: this branch predates the merges of #288 and #289, so much of its content is already on alpha, and it would need a rebase before being reviewable. Reopening deliberately, after a rebase, is preferable to leaving it open in this state.

@prisis prisis closed this Aug 2, 2026
@prisis
prisis deleted the fix/framework-adapter-upload-guards branch August 2, 2026 09:47
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using our GitHub Discussions tab for questions.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant