fix: replace as any with Partial<OEmbedMeta> in OEmbed meta parsing#39489
fix: replace as any with Partial<OEmbedMeta> in OEmbed meta parsing#39489Agarwalchetan wants to merge 4 commits intoRocketChat:developfrom
as any with Partial<OEmbedMeta> in OEmbed meta parsing#39489Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
WalkthroughType-only changes: Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/meteor/server/services/messages/hooks/AfterSaveOEmbed.ts (1)
241-281:⚠️ Potential issue | 🟠 MajorThe cast at line 281 masks an incomplete
OEmbedMeta.
Partial<OEmbedMeta>correctly reflects the local builder at line 241, butmeta: metas as OEmbedMetaat line 281 reintroduces type unsoundness at the boundary. The object is missingoembedUrl(which is required byOEmbedMetaasstring | string[]), andafterParseUrlContenthas early-return paths viacleanupOembedat lines 165-166 and 172 that can execute beforeoembedUrlis assigned at line 175. This allows callers to receive a value typed as completeOEmbedMetawhen it is actually missing required fields.Either ensure
oembedUrlis populated before the cast, or keep the boundary type asPartial<OEmbedMeta>until the provider pipeline guarantees all required fields.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/meteor/server/services/messages/hooks/AfterSaveOEmbed.ts` around lines 241 - 281, The code casts the local Partial<OEmbedMeta> variable metas to OEmbedMeta when calling afterParseUrlContent, which is unsafe because metas may lack required fields like oembedUrl (set later at line 175) and early returns (cleanupOembed) can occur beforehand; fix by either (A) ensuring metas.oembedUrl is definitely populated before the cast (assign oembedUrl where you build metas or before the afterParseUrlContent call) or (B) change the boundary to pass metas as Partial<OEmbedMeta> (adjust afterParseUrlContent signature/overloads or add a validation step that throws/returns early if required fields including oembedUrl are missing) so callers never receive an incomplete OEmbedMeta.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@apps/meteor/server/services/messages/hooks/AfterSaveOEmbed.ts`:
- Around line 241-281: The code casts the local Partial<OEmbedMeta> variable
metas to OEmbedMeta when calling afterParseUrlContent, which is unsafe because
metas may lack required fields like oembedUrl (set later at line 175) and early
returns (cleanupOembed) can occur beforehand; fix by either (A) ensuring
metas.oembedUrl is definitely populated before the cast (assign oembedUrl where
you build metas or before the afterParseUrlContent call) or (B) change the
boundary to pass metas as Partial<OEmbedMeta> (adjust afterParseUrlContent
signature/overloads or add a validation step that throws/returns early if
required fields including oembedUrl are missing) so callers never receive an
incomplete OEmbedMeta.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8d62f896-265f-4b33-91c9-0c6332f3dd23
📒 Files selected for processing (1)
apps/meteor/server/services/messages/hooks/AfterSaveOEmbed.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/server/services/messages/hooks/AfterSaveOEmbed.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.
📚 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/server/services/messages/hooks/AfterSaveOEmbed.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/server/services/messages/hooks/AfterSaveOEmbed.ts
…walchetan/Rocket.Chat into fix/oembed-meta-as-any-type
What
Removes the broad
as anytype assertion when initializing themetasobject in getUrlMeta() inside AfterSaveOEmbed.ts.Why
The previous code silenced TypeScript for the entire
metasobject:This means any typo in a key assignment or a wrong value type would go completely undetected. Since OEmbedMeta is defined as a string-indexed type, we can do better.
How
Use
Partial<OEmbedMeta>for the build phase — TypeScript can now validate all dynamic string key assignments — and propagatePartial<OEmbedMeta>all the way through afterParseUrlContent and cleanupOembed so no cast is needed at any call site:Changes
OEmbedMeta = {} as any→Partial<OEmbedMeta> = {}Line 281:
meta: metas as OEmbedMeta→meta: metas(cast removed)meta: OEmbedMeta→meta: Partial<OEmbedMeta>afterParseUrlContent input/output:
meta: OEmbedMeta→meta: Partial<OEmbedMeta>Removed
meta as OEmbedMetacast in cleanupOembed returnTesting
yarn tsc -p apps/meteor/tsconfig.json --noEmiton both the baseline (before) and the fix (after). Output is identical — zero new type errors introduced.Summary by CodeRabbit