feat(editor): update editor limits and add error boundary#1507
Conversation
- Reduced maximum document size for the editor from 5MB to 1MB. - Introduced a new line limit of 5000 for documents in the editor. - Implemented a PlateErrorBoundary component to handle rendering errors gracefully in the editor panel. - Updated logic in the editor panel to check both size and line count for document limits.
|
@AnishSarkar22 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughBackend reduces ChangesEditor line-count limits and PlateErrorBoundary
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 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. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
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 `@surfsense_web/components/editor-panel/editor-panel.tsx`:
- Around line 844-853: The fallback SourceCodeEditor within the
PlateErrorBoundary component is configured with readOnly set to true and an
empty onChange handler, which prevents users from continuing to edit if Plate
crashes. To fix this, remove the readOnly prop (or set it to false) and
implement a meaningful onChange handler that allows users to update the content.
Additionally, ensure the SourceCodeEditor binds to a state variable that tracks
the current in-memory draft rather than editorDoc.source_markdown, which may
contain stale saved content. This allows users to continue editing and preserve
their unsaved changes even if the Plate editor fails.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: b0b4bbac-0cc3-490c-b39e-a7b71ae4c9dd
📒 Files selected for processing (3)
surfsense_backend/app/routes/editor_routes.pysurfsense_web/components/editor-panel/editor-panel.tsxsurfsense_web/components/editor/plate-error-boundary.tsx
| <PlateErrorBoundary | ||
| key={`plate-boundary-${editorInstanceKey}`} | ||
| fallback={ | ||
| <SourceCodeEditor | ||
| path={`${editorDoc.title || "document"}.md`} | ||
| language="markdown" | ||
| value={editorDoc.source_markdown} | ||
| readOnly | ||
| onChange={() => {}} | ||
| /> |
There was a problem hiding this comment.
Fallback is locked read-only and can hide unsaved edits after a Plate crash.
On Line 847-Line 853, the boundary fallback always uses readOnly with a no-op onChange, and binds to editorDoc.source_markdown. If Plate fails while editing, users can’t continue in fallback and may see stale saved content instead of the in-memory draft.
Proposed fix
<PlateErrorBoundary
key={`plate-boundary-${editorInstanceKey}`}
fallback={
<SourceCodeEditor
path={`${editorDoc.title || "document"}.md`}
language="markdown"
- value={editorDoc.source_markdown}
- readOnly
- onChange={() => {}}
+ value={activeMarkdown}
+ readOnly={!isEditing}
+ onChange={(next) => {
+ if (!isEditing) return;
+ markdownRef.current = next;
+ const saved = editorDoc.source_markdown ?? "";
+ setEditedMarkdown(next === saved ? null : next);
+ }}
/>
}
>📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| <PlateErrorBoundary | |
| key={`plate-boundary-${editorInstanceKey}`} | |
| fallback={ | |
| <SourceCodeEditor | |
| path={`${editorDoc.title || "document"}.md`} | |
| language="markdown" | |
| value={editorDoc.source_markdown} | |
| readOnly | |
| onChange={() => {}} | |
| /> | |
| <PlateErrorBoundary | |
| key={`plate-boundary-${editorInstanceKey}`} | |
| fallback={ | |
| <SourceCodeEditor | |
| path={`${editorDoc.title || "document"}.md`} | |
| language="markdown" | |
| value={activeMarkdown} | |
| readOnly={!isEditing} | |
| onChange={(next) => { | |
| if (!isEditing) return; | |
| markdownRef.current = next; | |
| const saved = editorDoc.source_markdown ?? ""; | |
| setEditedMarkdown(next === saved ? null : next); | |
| }} | |
| /> | |
| } | |
| > |
🤖 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 `@surfsense_web/components/editor-panel/editor-panel.tsx` around lines 844 -
853, The fallback SourceCodeEditor within the PlateErrorBoundary component is
configured with readOnly set to true and an empty onChange handler, which
prevents users from continuing to edit if Plate crashes. To fix this, remove the
readOnly prop (or set it to false) and implement a meaningful onChange handler
that allows users to update the content. Additionally, ensure the
SourceCodeEditor binds to a state variable that tracks the current in-memory
draft rather than editorDoc.source_markdown, which may contain stale saved
content. This allows users to continue editing and preserve their unsaved
changes even if the Plate editor fails.
Description
Motivation and Context
FIX #
Screenshots
API Changes
Change Type
Testing Performed
Checklist
High-level PR Summary
This PR introduces stricter document size limits for the editor and adds error handling capabilities. The maximum document size is reduced from 5MB to 1MB, and a new line limit of 5000 lines is enforced to prevent performance issues. The backend now returns both size and line count information, which the frontend uses to determine whether to use the rich
plateeditor or fall back to the simplermonacoeditor. Additionally, a newPlateErrorBoundarycomponent wraps the editor to gracefully handle rendering errors by falling back to a read-only markdown view.⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
surfsense_backend/app/routes/editor_routes.pysurfsense_web/components/editor/plate-error-boundary.tsxsurfsense_web/components/editor-panel/editor-panel.tsxSummary by CodeRabbit