Skip to content

Conversation

@ColonelThirtyTwo
Copy link
Contributor

Dug deeper and filed ueberdosis/tiptap#7346 to TipTap. When useEditor's parameters change, it appears to call the useEditorState's selectors with an uninitialized editor, causing errors. This patch works around that by checking the editor's isInitialized field in each selector.

Dug deeper and filed ueberdosis/tiptap#7346 to
TipTap. When `useEditor`'s parameters change, it appears to call the
`useEditorState`'s selectors with an uninitialized editor, causing
errors. This patch works around that by checking the editor's
`isInitialized` field in each selector.
@codecov
Copy link

codecov bot commented Dec 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.34%. Comparing base (ba1b68d) to head (a697bf5).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #788   +/-   ##
=======================================
  Coverage   91.34%   91.34%           
=======================================
  Files         367      367           
  Lines       20728    20728           
=======================================
+ Hits        18934    18935    +1     
+ Misses       1794     1793    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

marcpfuller
marcpfuller previously approved these changes Dec 17, 2025
Copy link
Contributor

@marcpfuller marcpfuller left a comment

Choose a reason for hiding this comment

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

Looks good to me

Add an error boundary component that catches render errors and renders
an error alert. Previously React would simply remove the entire form
without conveying anything wrong to the user.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a recurring issue where the collaborative editor sometimes fails to load. The fix works around a TipTap bug where useEditor's parameters changes cause useEditorState selectors to be called with an uninitialized editor. The PR also adds an ErrorBoundary component to gracefully handle editor errors.

  • Adds isInitialized checks in all editor state selectors to prevent errors when the editor is not ready
  • Introduces an ErrorBoundary component to catch and display errors in the collaborative editor
  • Wraps all form components with ErrorBoundary for better error handling
  • Includes minor CSS formatting fixes (indentation and color hex case)

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
javascript/src/frontend/collab_forms/rich_text_editor/table.tsx Adds isInitialized check to TableCaptionBookmarkButton selector
javascript/src/frontend/collab_forms/rich_text_editor/link.tsx Adds isInitialized check to LinkButton selector
javascript/src/frontend/collab_forms/rich_text_editor/index.tsx Adds isInitialized check to FormatButton selector
javascript/src/frontend/collab_forms/rich_text_editor/heading.tsx Adds isInitialized check to HeadingIdButton selector
javascript/src/frontend/collab_forms/rich_text_editor/evidence/index.tsx Adds isInitialized check to EvidenceButton selector
javascript/src/frontend/collab_forms/rich_text_editor/color.tsx Adds isInitialized check to ColorButton selector
javascript/src/frontend/collab_forms/error_boundary.tsx New ErrorBoundary component to catch React errors and display user-friendly message
javascript/src/frontend/collab_forms/forms/reportobservationlink.tsx Wraps component with ErrorBoundary
javascript/src/frontend/collab_forms/forms/reportfindinglink.tsx Wraps component with ErrorBoundary
javascript/src/frontend/collab_forms/forms/report_field.tsx Wraps component with ErrorBoundary
javascript/src/frontend/collab_forms/forms/project_collabnote.tsx Wraps component with ErrorBoundary
javascript/src/frontend/collab_forms/forms/observation.tsx Wraps component with ErrorBoundary
javascript/src/frontend/collab_forms/forms/finding.tsx Wraps component with ErrorBoundary
javascript/src/frontend/collab_forms/editor.scss Fixes indentation and color hex formatting

selector: ({ editor }) =>
editor.can().setTableCaptionBookmark("example"),
selector: ({ editor }) => {
if (!editor.isInitialized) return { enabled: false, active: false };
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The selector returns an object { enabled: false, active: false } when the editor is not initialized (line 16), but returns a boolean from editor.can().setTableCaptionBookmark("example") when initialized (line 17). This type inconsistency will cause issues because the variable enabled on line 13 expects a consistent type. The selector should return the same type in both cases.

Suggested change
if (!editor.isInitialized) return { enabled: false, active: false };
if (!editor.isInitialized) return false;

Copilot uses AI. Check for mistakes.
this.state = { hasError: false };
}

static getDerivedStateFromError(error: Error) {
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The getDerivedStateFromError method has an error parameter that is declared but never used. Consider removing the parameter name or prefixing it with an underscore (e.g., _error) to indicate it's intentionally unused.

Suggested change
static getDerivedStateFromError(error: Error) {
static getDerivedStateFromError(_error: Error) {

Copilot uses AI. Check for mistakes.
return { hasError: true };
}

componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void {
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The componentDidCatch method has error and errorInfo parameters that are declared but never used. The comment indicates "React will print the error," but if this method serves no purpose beyond that, consider removing it entirely since React handles error logging by default. If you want to keep it for future error logging, prefix the parameters with underscores (e.g., _error, _errorInfo).

Suggested change
componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void {
componentDidCatch(_error: Error, _errorInfo: React.ErrorInfo): void {

Copilot uses AI. Check for mistakes.
@chrismaddalena chrismaddalena merged commit 9d4587d into GhostManager:master Dec 22, 2025
8 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.

3 participants