Skip to content

feat(editor): update editor limits and add error boundary#1507

Merged
MODSetter merged 1 commit into
MODSetter:mainfrom
AnishSarkar22:fix/documents-editor
Jun 17, 2026
Merged

feat(editor): update editor limits and add error boundary#1507
MODSetter merged 1 commit into
MODSetter:mainfrom
AnishSarkar22:fix/documents-editor

Conversation

@AnishSarkar22

@AnishSarkar22 AnishSarkar22 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator
  • 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.

Description

Motivation and Context

FIX #

Screenshots

API Changes

  • This PR includes API changes

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring
  • Documentation
  • Dependency/Build system
  • Breaking change
  • Other (specify):

Testing Performed

  • Tested locally
  • Manual/QA verification

Checklist

  • Follows project coding standards and conventions
  • Documentation updated as needed
  • Dependencies updated as needed
  • No lint/build errors or new warnings
  • All relevant tests are passing

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 plate editor or fall back to the simpler monaco editor. Additionally, a new PlateErrorBoundary component 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
Order File Path
1 surfsense_backend/app/routes/editor_routes.py
2 surfsense_web/components/editor/plate-error-boundary.tsx
3 surfsense_web/components/editor-panel/editor-panel.tsx

Need help? Join our Discord

Summary by CodeRabbit

  • New Features
    • Editor now tracks line counts in documents alongside file size
    • Enhanced size limit warnings display both file bytes and line counts simultaneously
    • Document automatically switches to read-only mode when limits are exceeded
    • Improved error handling to maintain editor stability during unexpected failures
    • Updated editor size constraints: reduced file limit to 1 MB (from 5 MB) with new 5,000 line maximum

- 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.
@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown

@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.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Backend reduces EDITOR_PLATE_MAX_BYTES to 1 MB and adds a new 5000-line EDITOR_PLATE_MAX_LINES constant; the response helper now computes line_count, gates viewer_mode on either limit, and includes both limits in the payload. The frontend consumes these new fields through an updated EditorContent type, a countLines utility, and expanded threshold logic for near/over-limit warnings and save guards. A new PlateErrorBoundary class component wraps Plate rendering with a SourceCodeEditor fallback keyed by editorInstanceKey.

Changes

Editor line-count limits and PlateErrorBoundary

Layer / File(s) Summary
Backend limit constants and response metadata
surfsense_backend/app/routes/editor_routes.py
EDITOR_PLATE_MAX_BYTES reduced to 1 MB; EDITOR_PLATE_MAX_LINES (5000) added. _build_response computes line_count, derives too_large from both thresholds, sets viewer_mode, and returns line_count, editor_plate_max_bytes, and editor_plate_max_lines in the payload.
PlateErrorBoundary component
surfsense_web/components/editor/plate-error-boundary.tsx, surfsense_web/components/editor-panel/editor-panel.tsx
New "use client" React class component with children/fallback props and hasError state; getDerivedStateFromError catches render failures. Import added to EditorPanelContent.
EditorContent shape, constants, and countLines utility
surfsense_web/components/editor-panel/editor-panel.tsx
LARGE_DOCUMENT_THRESHOLD lowered to 1 MB; line_count and editor_plate_max_lines added to the EditorContent interface; countLines helper introduced.
Viewer mode and limit threshold computation
surfsense_web/components/editor-panel/editor-panel.tsx
plateMaxLines and docLineCount derived from EditorContent or counted from source_markdown; isLargeDocument, viewerMode, isNearPlateLimit (90% threshold), and isOverPlateLimit all updated to evaluate both byte-size and line-count dimensions.
Save guards, instance key, alert text, and Plate rendering
surfsense_web/components/editor-panel/editor-panel.tsx
Save-limit check extended with savedLineCount > plateMaxLines; plateMaxLines added to handleSave dependencies; editorInstanceKey introduced; large-document alert updated to show formatBytes + docLineCount; Plate editor wrapped in PlateErrorBoundary with a SourceCodeEditor fallback; plate-limit warning now shows byte and line counts against both thresholds.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 A megabyte's cut, now a million's the top,
Five thousand lines hit and the Plate editor stops.
An error boundary catches what might go wrong,
With Monaco standing by, sturdy and strong.
The rabbit counts lines with a flick of the paw —
No document too large for this vigilant claw! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: updating editor limits (max bytes and lines) and adding the PlateErrorBoundary error handling component.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7ce409c and 4658130.

📒 Files selected for processing (3)
  • surfsense_backend/app/routes/editor_routes.py
  • surfsense_web/components/editor-panel/editor-panel.tsx
  • surfsense_web/components/editor/plate-error-boundary.tsx

Comment on lines +844 to +853
<PlateErrorBoundary
key={`plate-boundary-${editorInstanceKey}`}
fallback={
<SourceCodeEditor
path={`${editorDoc.title || "document"}.md`}
language="markdown"
value={editorDoc.source_markdown}
readOnly
onChange={() => {}}
/>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Suggested change
<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.

@MODSetter MODSetter merged commit 77688ac into MODSetter:main Jun 17, 2026
6 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants