feat: Validate code: application/json settings on UI - #41142
Conversation
… flag, tidy save gating
|
Looks like this PR is ready to merge! 🎉 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📜 Recent review details⏰ Context from checks skipped due to timeout. (5)
🧰 Additional context used📓 Path-based instructions (1)**/*.{ts,tsx,js}📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
Files:
🧠 Learnings (3)📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
📚 Learning: 2026-05-06T12:21:44.083ZApplied to files:
🔇 Additional comments (1)
WalkthroughThis PR adds inline JSON validation for admin code-based settings, propagates invalid state through the editor and settings form, blocks saving malformed JSON, and marks LDAP map settings as JSON code. It also adds the ChangesJSON Setting Validation Feedback
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant Setting
participant CodeSettingInput
participant CodeMirrorBox
participant getCodeSettingError
participant SettingsGroupPage
participant SettingsProvider
User->>Setting: edits JSON value
Setting->>getCodeSettingError: validate current value
getCodeSettingError-->>Setting: errorKey or undefined
Setting->>CodeSettingInput: pass translated error
CodeSettingInput->>CodeMirrorBox: error prop
CodeMirrorBox-->>User: render inline FieldError
Setting->>SettingsGroupPage: mark setting invalid
User->>SettingsGroupPage: click Save changes
SettingsGroupPage->>SettingsProvider: dispatch(changes)
SettingsProvider->>getCodeSettingError: re-validate code setting
SettingsProvider-->>User: stop save when invalid
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
🦋 Changeset detectedLatest commit: 7f42dd6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #41142 +/- ##
===========================================
+ Coverage 69.16% 69.23% +0.06%
===========================================
Files 3433 3436 +3
Lines 132323 132677 +354
Branches 23087 23144 +57
===========================================
+ Hits 91518 91854 +336
+ Misses 37455 37450 -5
- Partials 3350 3373 +23
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx (1)
79-81: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueRedundant guard given disabled Save button, but reasonable defensive check.
changesis still built (lines 64-77) before theisSaveDisabledearly return; harmless given the small array size, but if you want to shave the extra work, move the check above thechangescomputation.🤖 Prompt for 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. In `@apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx` around lines 79 - 81, The save handler in SettingsGroupPage still builds the changes array before the early return, so the disabled-state guard is only preventing the mutation step after some unnecessary work. Move the isSaveDisabled check in SettingsGroupPage before the changes computation inside the save flow so the handler exits immediately when saving is disabled. Use the existing save handler logic and the isSaveDisabled flag to keep the optimization local and avoid recalculating changes when no save can occur.apps/meteor/client/views/admin/settings/Setting/Setting.tsx (1)
56-61: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueAvoid the extra
invaliddispatch on each keystroke. This updates the store twice per change here and again in the 230ms debouncedupdate, which re-runsSettingsGroupPageand otherEditableSettingsContextconsumers more often than necessary. If instant Save-state feedback is required, keep that on a separate fast path; otherwise let the debounced update owninvalidtoo.🤖 Prompt for 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. In `@apps/meteor/client/views/admin/settings/Setting/Setting.tsx` around lines 56 - 61, The Setting input handler is dispatching `invalid` immediately on every change and then again in the debounced update, causing duplicate store updates. In `Setting.tsx`, adjust the `handleChange`/debounced `update` flow so `invalid` is set in only one place: either remove the immediate `invalid` dispatch and let the 230ms `update` own it, or split Save-state feedback into a separate fast path without updating the store twice. Use the `update` callback and `getCodeSettingError` logic to locate the affected dispatch.
🤖 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/providers/SettingsProvider.tsx`:
- Around line 119-129: The invalid code-setting guard in SettingsProvider should
not silently return when a bad value is detected; instead, make the settings
dispatch path reject with an Error from the code-setting check in
SettingsProvider so callers can surface it. Update the direct callers that use
useSettingsDispatch, specifically SettingField and AdminFeaturePreviewPage, to
catch the rejection and show feedback rather than dropping the change. Keep
SettingsGroupPage working with the same dispatch contract by handling the error
there as well.
In
`@apps/meteor/client/views/admin/settings/Setting/inputs/CodeMirror/CodeMirrorBox.tsx`:
- Around line 7-8: Remove the implementation comment above editorBorderProps in
CodeMirrorBox and keep the constant as-is; the rationale comment should be
dropped to match the no-code-comments guideline for implementation files. Locate
the change in CodeMirrorBox.tsx by the editorBorderProps declaration and delete
only the added explanatory comment.
- Line 1: The CodeMirror validation message is rendered via FieldError but the
editor control is not linked to it for assistive technologies. Update
CodeMirrorBox to give the error text a stable id and wire that id into the
CodeMirror editor’s aria-describedby/accessible description so the editor is
associated with the rendered error state.
---
Nitpick comments:
In `@apps/meteor/client/views/admin/settings/Setting/Setting.tsx`:
- Around line 56-61: The Setting input handler is dispatching `invalid`
immediately on every change and then again in the debounced update, causing
duplicate store updates. In `Setting.tsx`, adjust the `handleChange`/debounced
`update` flow so `invalid` is set in only one place: either remove the immediate
`invalid` dispatch and let the 230ms `update` own it, or split Save-state
feedback into a separate fast path without updating the store twice. Use the
`update` callback and `getCodeSettingError` logic to locate the affected
dispatch.
In
`@apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx`:
- Around line 79-81: The save handler in SettingsGroupPage still builds the
changes array before the early return, so the disabled-state guard is only
preventing the mutation step after some unnecessary work. Move the
isSaveDisabled check in SettingsGroupPage before the changes computation inside
the save flow so the handler exits immediately when saving is disabled. Use the
existing save handler logic and the isSaveDisabled flag to keep the optimization
local and avoid recalculating changes when no save can occur.
🪄 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: 73894d57-6066-4f3f-bc3d-2454f612f6bb
📒 Files selected for processing (15)
.changeset/json-setting-validation-feedback.mdapps/meteor/client/lib/utils/getCodeSettingError.spec.tsapps/meteor/client/lib/utils/getCodeSettingError.tsapps/meteor/client/lib/utils/isInvalidJSONValue.spec.tsapps/meteor/client/lib/utils/isInvalidJSONValue.tsapps/meteor/client/providers/SettingsProvider.tsxapps/meteor/client/views/admin/EditableSettingsContext.tsapps/meteor/client/views/admin/settings/Setting/Setting.tsxapps/meteor/client/views/admin/settings/Setting/inputs/CodeMirror/CodeMirrorBox.tsxapps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.spec.tsxapps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.tsxapps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsxapps/meteor/ee/server/settings/ldap.tsapps/meteor/server/settings/ldap.tspackages/i18n/src/locales/en.i18n.json
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
- GitHub Check: Hacktron Security Check
🧰 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/utils/getCodeSettingError.spec.tsapps/meteor/client/lib/utils/getCodeSettingError.tsapps/meteor/client/lib/utils/isInvalidJSONValue.tsapps/meteor/client/lib/utils/isInvalidJSONValue.spec.tsapps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.spec.tsxapps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.tsxapps/meteor/server/settings/ldap.tsapps/meteor/ee/server/settings/ldap.tsapps/meteor/client/views/admin/settings/Setting/inputs/CodeMirror/CodeMirrorBox.tsxapps/meteor/client/providers/SettingsProvider.tsxapps/meteor/client/views/admin/EditableSettingsContext.tsapps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsxapps/meteor/client/views/admin/settings/Setting/Setting.tsx
**/*.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/utils/getCodeSettingError.spec.tsapps/meteor/client/lib/utils/isInvalidJSONValue.spec.ts
🧠 Learnings (9)
📚 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/utils/getCodeSettingError.spec.tsapps/meteor/client/lib/utils/getCodeSettingError.tsapps/meteor/client/lib/utils/isInvalidJSONValue.tsapps/meteor/client/lib/utils/isInvalidJSONValue.spec.tsapps/meteor/client/views/admin/EditableSettingsContext.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/utils/getCodeSettingError.spec.tsapps/meteor/client/lib/utils/getCodeSettingError.tsapps/meteor/client/lib/utils/isInvalidJSONValue.tsapps/meteor/client/lib/utils/isInvalidJSONValue.spec.tsapps/meteor/client/views/admin/EditableSettingsContext.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/utils/getCodeSettingError.spec.tsapps/meteor/client/lib/utils/isInvalidJSONValue.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/utils/getCodeSettingError.spec.tsapps/meteor/client/lib/utils/getCodeSettingError.tsapps/meteor/client/lib/utils/isInvalidJSONValue.tsapps/meteor/client/lib/utils/isInvalidJSONValue.spec.tsapps/meteor/server/settings/ldap.tsapps/meteor/ee/server/settings/ldap.tsapps/meteor/client/views/admin/EditableSettingsContext.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/utils/getCodeSettingError.spec.tsapps/meteor/client/lib/utils/getCodeSettingError.tsapps/meteor/client/lib/utils/isInvalidJSONValue.tsapps/meteor/client/lib/utils/isInvalidJSONValue.spec.tsapps/meteor/server/settings/ldap.tsapps/meteor/ee/server/settings/ldap.tsapps/meteor/client/views/admin/EditableSettingsContext.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/utils/getCodeSettingError.spec.tsapps/meteor/client/lib/utils/isInvalidJSONValue.spec.tsapps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.spec.tsx
📚 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/utils/getCodeSettingError.spec.tsapps/meteor/client/lib/utils/getCodeSettingError.tsapps/meteor/client/lib/utils/isInvalidJSONValue.tsapps/meteor/client/lib/utils/isInvalidJSONValue.spec.tsapps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.spec.tsxapps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.tsxapps/meteor/server/settings/ldap.tsapps/meteor/ee/server/settings/ldap.tsapps/meteor/client/views/admin/settings/Setting/inputs/CodeMirror/CodeMirrorBox.tsxapps/meteor/client/providers/SettingsProvider.tsxapps/meteor/client/views/admin/EditableSettingsContext.tsapps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsxapps/meteor/client/views/admin/settings/Setting/Setting.tsx
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.
Applied to files:
.changeset/json-setting-validation-feedback.md
📚 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/views/admin/settings/Setting/inputs/CodeSettingInput.spec.tsxapps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.tsxapps/meteor/client/views/admin/settings/Setting/inputs/CodeMirror/CodeMirrorBox.tsxapps/meteor/client/providers/SettingsProvider.tsxapps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsxapps/meteor/client/views/admin/settings/Setting/Setting.tsx
🔇 Additional comments (15)
apps/meteor/ee/server/settings/ldap.ts (1)
139-145: LGTM!Also applies to: 259-265, 304-310
apps/meteor/server/settings/ldap.ts (1)
229-235: LGTM!packages/i18n/src/locales/en.i18n.json (1)
2799-2799: LGTM!.changeset/json-setting-validation-feedback.md (1)
2-6: LGTM!apps/meteor/client/providers/SettingsProvider.tsx (1)
2-2: LGTM!Also applies to: 15-15
apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx (2)
49-51: LGTM!
168-168: LGTM!apps/meteor/client/lib/utils/isInvalidJSONValue.ts (1)
1-12: LGTM!apps/meteor/client/lib/utils/isInvalidJSONValue.spec.ts (1)
3-21: LGTM!apps/meteor/client/views/admin/EditableSettingsContext.ts (1)
7-12: LGTM!apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.spec.tsx (1)
1-34: LGTM!apps/meteor/client/lib/utils/getCodeSettingError.ts (1)
1-17: LGTM!apps/meteor/client/lib/utils/getCodeSettingError.spec.ts (1)
1-24: LGTM!apps/meteor/client/views/admin/settings/Setting/Setting.tsx (1)
2-2: LGTM!Also applies to: 12-12, 40-41
apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.tsx (1)
2-4: LGTM!Also applies to: 32-34, 48-48
There was a problem hiding this comment.
4 issues found across 15 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
BE looks fine |
There was a problem hiding this comment.
1 issue found across 7 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Proposed changes (including videos or screenshots)
Issue(s)
https://rocketchat.atlassian.net/browse/CORE-2361
Steps to test or reproduce
Further comments
Screen.Recording.2026-07-01.at.12.38.48.PM.mov
Summary by CodeRabbit