Skip to content

[8320] RTE fails silently on initialization in XB when <!DOCTYPE html> is missing#4809

Open
jvega190 wants to merge 2 commits intocraftercms:developfrom
jvega190:bugfix/8320
Open

[8320] RTE fails silently on initialization in XB when <!DOCTYPE html> is missing#4809
jvega190 wants to merge 2 commits intocraftercms:developfrom
jvega190:bugfix/8320

Conversation

@jvega190
Copy link
Member

@jvega190 jvega190 commented Feb 18, 2026

craftercms/craftercms#8320

Summary by CodeRabbit

  • Bug Fixes
    • RTE now detects missing document type and aborts initialization gracefully, unlocking the item and showing a clear error guiding users to contact their administrator.
  • Localization
    • Added a user-facing error message for the RTE initialization failure when no document type is found.

@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

No actionable comments were generated in the recent review. 🎉


Walkthrough

Adds a missing-doctype runtime guard to Rich Text Editor initialization: detects absent document.doctype, logs an error, shows a user-facing snack message, unlocks the current item, and aborts editor initialization. Also adds a new translation key for the error message.

Changes

Cohort / File(s) Summary
Translation Messages
ui/app/src/assets/guestMessages.ts
Added noDocTypeError translation entry (validations.noDocTypeError) with default message for RTE initialization failure due to missing document type.
RTE Error Handling
ui/guest/src/controls/rte.ts
Added runtime guard in initTinyMCE to check document.doctype; on missing doctype, log error, display snack message, unlock item, and abort by returning NEVER. Added imports for NEVER and nou.

Sequence Diagram(s)

sequenceDiagram
    participant RTE as initTinyMCE
    participant Doc as document
    participant Logger as Logger
    participant Snack as SnackService
    participant Lock as LockService
    participant Rx as RxJS

    RTE->>Doc: check document.doctype
    alt doctype present
        RTE->>RTE: continue TinyMCE init flow
    else doctype missing
        RTE->>Logger: log error "no doctype"
        RTE->>Snack: show `validations.noDocTypeError`
        RTE->>Lock: unlock current item
        RTE->>Rx: return NEVER (abort initialization)
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only contains a GitHub issue link without following the template's requirement for ticket reference or full description. Expand the description to include a brief explanation of the issue, root cause, solution, and how the changes address the problem.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing RTE silent failure when DOCTYPE is missing, directly matching the code modifications.

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

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
ui/guest/src/controls/rte.ts (1)

118-128: Replace NEVER with EMPTY in the error path to allow the subscription to complete properly.

In the normal flow, the observable completes when the editor is closed (line 289: dispatch$.complete()). However, the error condition at line 127 returns NEVER, which never emits, errors, or completes. Since this function is consumed via switchMap in a Redux-Observable epic (root.ts, line 610), returning NEVER leaves the subscription open indefinitely instead of signaling completion. Returning EMPTY completes immediately, maintaining the semantic consistency of the observable contract.

♻️ Suggested change
-import { NEVER, Observable, Subject } from 'rxjs';
+import { EMPTY, NEVER, Observable, Subject } from 'rxjs';
-		return NEVER;
+		return EMPTY;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ui/guest/src/controls/rte.ts` around lines 118 - 128, The error branch
returns RxJS constant NEVER which never completes; replace it with EMPTY so the
observable completes immediately; update the code in the block that checks
nou(document.doctype) (where snackGuestMessage and unlockItem({ path }) are
posted) to return EMPTY instead of NEVER and ensure EMPTY is imported from
'rxjs' so the epic consuming this via switchMap can complete correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ui/guest/src/controls/rte.ts`:
- Around line 118-128: The guard that checks document.doctype and returns NEVER
must be moved to the top of the function before any DOM mutations (before code
that uses isRecordElInline, before hiding recordEl, inserting blockEl, and
before calling record.element.classList.remove(emptyFieldClass)); update the
function so the doctype check runs first and triggers the error log,
snackGuestMessage post, post(unlockItem({ path })), and return NEVER immediately
(so cancel() wired in tinymce setup is not needed), ensuring no DOM changes
occur when document.doctype is absent.

---

Nitpick comments:
In `@ui/guest/src/controls/rte.ts`:
- Around line 118-128: The error branch returns RxJS constant NEVER which never
completes; replace it with EMPTY so the observable completes immediately; update
the code in the block that checks nou(document.doctype) (where snackGuestMessage
and unlockItem({ path }) are posted) to return EMPTY instead of NEVER and ensure
EMPTY is imported from 'rxjs' so the epic consuming this via switchMap can
complete correctly.

@jvega190 jvega190 marked this pull request as ready for review February 18, 2026 20:25
@jvega190 jvega190 requested a review from rart as a code owner February 18, 2026 20:25
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.

1 participant

Comments