refactor(client): centralize DDP wire codec behind sdk/ddpProtocol#40486
Conversation
|
Looks like this PR is ready to merge! 🎉 |
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds a local DDP codec module and migrates client-side parsing/serialization calls from Meteor's DDPCommon to that module across SDK client bridging, collection handlers, REST transport overrides, stub streams, and tests. ChangesDDP Protocol Codec Abstraction
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
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. Comment |
|
/jira ARCH-2116 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #40486 +/- ##
========================================
Coverage 69.61% 69.62%
========================================
Files 3325 3326 +1
Lines 122797 122807 +10
Branches 21831 21863 +32
========================================
+ Hits 85490 85504 +14
+ Misses 33957 33945 -12
- Partials 3350 3358 +8
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
16cf6a4 to
f60b056
Compare
addc58e to
fbf06fc
Compare
f60b056 to
eba2310
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/meteor/client/lib/sdk/ddpSdk.ts`:
- Around line 145-149: Stored-token rejection currently clears storage and calls
Meteor.connection.setUserId(null) but does not notify account.onLogout
subscribers (so CachedStoresManager.clearAllCachesOnLogout etc. aren't run);
after clearing storage and setting userId to null, explicitly invoke the SDK's
logout notification pipeline to run registered onLogout callbacks (e.g. call a
method on getDdpSdk().account such as _runLogoutHandlers / _runOnLogoutCallbacks
or whatever internal runner exists) so that subscribers registered via
getDdpSdk().account.onLogout() are executed; modify the cleanup path around
Meteor.connection.setUserId(null) to call that runner immediately (or, if no
runner exists, iterate over the stored onLogout callbacks on getDdpSdk().account
and invoke them) to ensure logout side effects run without calling
Meteor.logout().
In
`@apps/meteor/client/providers/AuthenticationProvider/AuthenticationProvider.tsx`:
- Around line 155-164: The wipeLocalAuth implementation clears storage and calls
Meteor.connection.setUserId(null) which bypasses the Accounts/DDL logout hooks
and leaves subscribers like CachedStoresManager stale; replace the direct
setUserId(null) path by invoking the SDK logout flow (call getDdpSdk().logout()
from inside wipeLocalAuth) so Accounts.onLogout / getDdpSdk().account.onLogout()
handlers run, or if the ddpSdk race concern applies in this force-logout code
path, explicitly trigger the registered logout callbacks used by
CachedStoresManager after clearing storage; update the wipeLocalAuth function to
use getDdpSdk().logout() (or call the same logout callbacks that
CachedStoresManager subscribes to) instead of Meteor.connection.setUserId(null).
- Around line 38-48: The installed flag is set too early in
installLoggingInBridge causing a permanent no-op if Accounts._setLoggingIn is
missing on first call; change installLoggingInBridge so it only sets
loggingInBridgeInstalled = true after verifying typeof wrap._setLoggingIn ===
'function' and after assigning wrap._setLoggingIn to the wrapper that calls
original.call(...) and loggingInListeners.forEach(...), i.e., perform the
runtime check and replacement first (using the wrap and original variables) and
then mark loggingInBridgeInstalled true to ensure future calls short-circuit
only after a successful attachment.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6df056ff-1a7c-425a-b4b6-3ebd82d91187
📒 Files selected for processing (14)
apps/meteor/app/utils/client/lib/SDKClient.tsapps/meteor/client/hooks/useReactiveValue.tsapps/meteor/client/lib/cachedStores/CachedStoresManager.tsapps/meteor/client/lib/sdk/ddpProtocol.tsapps/meteor/client/lib/sdk/ddpSdk.tsapps/meteor/client/lib/sdk/meteorBackedSdk.tsapps/meteor/client/lib/sdk/storage.tsapps/meteor/client/meteor/overrides/ddpOverREST.tsapps/meteor/client/meteor/overrides/ddpSdkCollectionBridge.tsapps/meteor/client/meteor/overrides/index.tsapps/meteor/client/meteor/overrides/stubMeteorStream.tsapps/meteor/client/meteor/overrides/unstoreLoginToken.tsapps/meteor/client/providers/AuthenticationProvider/AuthenticationProvider.tsxapps/meteor/client/providers/ServerProvider.tsx
💤 Files with no reviewable changes (3)
- apps/meteor/client/hooks/useReactiveValue.ts
- apps/meteor/client/meteor/overrides/unstoreLoginToken.ts
- apps/meteor/client/meteor/overrides/index.ts
✅ Files skipped from review due to trivial changes (1)
- apps/meteor/client/lib/sdk/meteorBackedSdk.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- apps/meteor/client/meteor/overrides/stubMeteorStream.ts
- apps/meteor/client/meteor/overrides/ddpOverREST.ts
- apps/meteor/client/meteor/overrides/ddpSdkCollectionBridge.ts
- apps/meteor/client/lib/sdk/ddpProtocol.ts
- apps/meteor/app/utils/client/lib/SDKClient.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
apps/meteor/client/lib/cachedStores/CachedStoresManager.tsapps/meteor/client/lib/sdk/storage.tsapps/meteor/client/lib/sdk/ddpSdk.tsapps/meteor/client/providers/AuthenticationProvider/AuthenticationProvider.tsxapps/meteor/client/providers/ServerProvider.tsx
🧠 Learnings (6)
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.
Applied to files:
apps/meteor/client/lib/cachedStores/CachedStoresManager.tsapps/meteor/client/lib/sdk/storage.tsapps/meteor/client/lib/sdk/ddpSdk.ts
📚 Learning: 2026-05-11T20:30:35.265Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 40480
File: apps/meteor/client/meteor/startup/accounts.ts:59-61
Timestamp: 2026-05-11T20:30:35.265Z
Learning: In Rocket.Chat’s Meteor client code, when calling `dispatchToastMessage` with `{ type: 'error' }`, pass the raw caught error object as `message` without manual normalization. `dispatchToastMessage` is designed to accept `message: unknown` for error toasts, so avoid converting errors to strings (e.g., `String(error)`) or extracting `error.message` before passing them.
Applied to files:
apps/meteor/client/lib/cachedStores/CachedStoresManager.tsapps/meteor/client/lib/sdk/storage.tsapps/meteor/client/lib/sdk/ddpSdk.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
apps/meteor/client/lib/cachedStores/CachedStoresManager.tsapps/meteor/client/lib/sdk/storage.tsapps/meteor/client/lib/sdk/ddpSdk.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
apps/meteor/client/lib/cachedStores/CachedStoresManager.tsapps/meteor/client/lib/sdk/storage.tsapps/meteor/client/lib/sdk/ddpSdk.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.
Applied to files:
apps/meteor/client/lib/cachedStores/CachedStoresManager.tsapps/meteor/client/lib/sdk/storage.tsapps/meteor/client/lib/sdk/ddpSdk.tsapps/meteor/client/providers/AuthenticationProvider/AuthenticationProvider.tsxapps/meteor/client/providers/ServerProvider.tsx
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.
Applied to files:
apps/meteor/client/providers/AuthenticationProvider/AuthenticationProvider.tsxapps/meteor/client/providers/ServerProvider.tsx
🔇 Additional comments (3)
apps/meteor/client/lib/sdk/storage.ts (1)
9-9: LGTM!apps/meteor/client/lib/cachedStores/CachedStoresManager.ts (1)
2-2: LGTM!Also applies to: 20-21
apps/meteor/client/providers/ServerProvider.tsx (1)
15-15: LGTM!Also applies to: 129-159, 164-164
Five client modules each imported DDPCommon.parseDDP / stringifyDDP from meteor/ddp-common to encode and decode DDP frames. The codec itself is a small concern, but every direct import is a Meteor dependency we'll need to migrate again when we swap to a standalone EJSON helper. Introduce apps/meteor/client/lib/sdk/ddpProtocol.ts as the single entry point. It re-exports parseDDP / stringifyDDP from DDPCommon (with a DDPMessage type alias for the stringifyDDP parameter shape) and is the only file on the client that imports from meteor/ddp-common. The future EJSON swap is one file change. Migrate the five consumers (SDKClient, meteorBackedSdk, ddpOverREST, ddpSdkCollectionBridge, stubMeteorStream) to import from the new module. Drop the verbose Parameters<typeof DDPCommon.stringifyDDP>[0] casts in favour of the exported DDPMessage type. No behaviour change: same DDPCommon implementation under the hood.
eba2310 to
9d906da
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/meteor/client/lib/presence.spec.ts`:
- Around line 9-12: The DDP mock uses JSON.parse/JSON.stringify which doesn't
preserve EJSON types; update the mock to use EJSON by importing the ejson
package and replacing DDPCommon.parseDDP and DDPCommon.stringifyDDP
implementations to call EJSON.parse and EJSON.stringify respectively; ensure the
import (e.g., import EJSON from 'ejson' or the correct default/named import) is
added at the top of presence.spec.ts so the mock behavior matches the production
DDP codec used in ddpSdk.ts.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 763b9122-b400-43e3-803f-153030aa26bf
📒 Files selected for processing (2)
apps/meteor/client/lib/presence.spec.tsapps/meteor/tests/mocks/client/meteor.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: 🔎 Code Check / TypeScript
- GitHub Check: 🔎 Code Check / Code Lint
- GitHub Check: 🔨 Test Storybook / Test Storybook
- GitHub Check: 🔨 Test Unit / Unit Tests
- GitHub Check: 📦 Meteor Build (coverage)
- GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
apps/meteor/client/lib/presence.spec.tsapps/meteor/tests/mocks/client/meteor.ts
**/*.spec.ts
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.spec.ts: Use descriptive test names that clearly communicate expected behavior in Playwright tests
Use.spec.tsextension for test files (e.g.,login.spec.ts)
Files:
apps/meteor/client/lib/presence.spec.ts
🧠 Learnings (7)
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.
Applied to files:
apps/meteor/client/lib/presence.spec.ts
📚 Learning: 2026-05-11T20:30:35.265Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 40480
File: apps/meteor/client/meteor/startup/accounts.ts:59-61
Timestamp: 2026-05-11T20:30:35.265Z
Learning: In Rocket.Chat’s Meteor client code, when calling `dispatchToastMessage` with `{ type: 'error' }`, pass the raw caught error object as `message` without manual normalization. `dispatchToastMessage` is designed to accept `message: unknown` for error toasts, so avoid converting errors to strings (e.g., `String(error)`) or extracting `error.message` before passing them.
Applied to files:
apps/meteor/client/lib/presence.spec.ts
📚 Learning: 2026-02-24T19:22:48.358Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/omnichannel/omnichannel-send-pdf-transcript.spec.ts:66-67
Timestamp: 2026-02-24T19:22:48.358Z
Learning: In Playwright end-to-end tests (e.g., under apps/meteor/tests/e2e/...), prefer locating elements by translated text (getByText) and ARIA roles (getByRole) over data-qa attributes. If translation values change, update the corresponding test locators accordingly. Never use data-qa locators. This guideline applies to all Playwright e2e test specs in the repository and helps keep tests robust to UI text changes and accessible semantics.
Applied to files:
apps/meteor/client/lib/presence.spec.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
apps/meteor/client/lib/presence.spec.tsapps/meteor/tests/mocks/client/meteor.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
apps/meteor/client/lib/presence.spec.tsapps/meteor/tests/mocks/client/meteor.ts
📚 Learning: 2026-03-06T18:10:15.268Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/code/CodeBlock.spec.tsx:47-68
Timestamp: 2026-03-06T18:10:15.268Z
Learning: In tests (especially those using testing-library/dom/jsdom) for Rocket.Chat components, the HTML <code> element has an implicit ARIA role of 'code'. Therefore, screen.getByRole('code') or screen.findByRole('code') will locate <code> elements even without a role attribute. Do not flag findByRole('code') as invalid in reviews; prefer using the implicit role instead of adding role="code" unless necessary for accessibility.
Applied to files:
apps/meteor/client/lib/presence.spec.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.
Applied to files:
apps/meteor/client/lib/presence.spec.tsapps/meteor/tests/mocks/client/meteor.ts
🔇 Additional comments (1)
apps/meteor/tests/mocks/client/meteor.ts (1)
54-57: ⚡ Quick winMock DDPCommon codec should preserve type fidelity, but the suggested fix is unfeasible.
The concern about DDP using JSON instead of EJSON is valid—DDP in production uses EJSON to preserve types like
Date. However, the suggested patch referencesEJSON.parse()andEJSON.stringify(), which do not exist on the mockedEJSONobject (the mock only providesisBinary,clone, andequals).To fix this properly, extend the mock's
EJSONobject withparseandstringifymethods, or alternatively use a different approach to ensure type-aware codec behavior in this mock.> Likely an incorrect or invalid review comment.
Summary
Five client modules each imported
DDPCommon.parseDDP/stringifyDDPfrommeteor/ddp-commonto encode and decode DDP frames. The codec itself is a small concern, but every direct import is a Meteor dependency we'll need to migrate again when we swap to a standalone EJSON helper.Introduce
apps/meteor/client/lib/sdk/ddpProtocol.tsas the single entry point. It re-exportsparseDDP/stringifyDDPfromDDPCommon(with aDDPMessagetype alias for thestringifyDDPparameter shape) and is the only file on the client that imports frommeteor/ddp-common. The future EJSON swap is one file change.Migrate the five consumers to import from the new module:
app/utils/client/lib/SDKClient.tsclient/lib/sdk/meteorBackedSdk.tsclient/meteor/overrides/ddpOverREST.tsclient/meteor/overrides/ddpSdkCollectionBridge.tsclient/meteor/overrides/stubMeteorStream.tsDrop the verbose
Parameters<typeof DDPCommon.stringifyDDP>[0]casts in favour of the exportedDDPMessagetype.No behaviour change: same
DDPCommonimplementation under the hood.Test plan
yarn eslinton the 6 changed files: 0 errors.tsc --noEmitonapps/meteoris clean.grepconfirms onlyddpProtocol.tsimports frommeteor/ddp-commonon the client side.Use_RC_SDKenabled): login and method calls routed through ddpOverREST and the stub stream both work — frames serialize/deserialize identically.ddpOverRESTcatch branch runs; the 2FA /totp-requiredflow still opens the modal.Summary by CodeRabbit
Task: ARCH-2139