Fix/docx import empty links - #2127
Open
samark231 wants to merge 2 commits into
Open
Conversation
…corrupt links never persist
…des gracefully instead of crashing the page
Deploying frontend-admin-dashboard with
|
| Latest commit: |
da60a28
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f2b0c88f.frontend-admin-dashboard.pages.dev |
| Branch Preview URL: | https://fix-docx-import-empty-links.frontend-admin-dashboard.pages.dev |
Contributor
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 8 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Root-cause follow-up to the earlier slide-editor crash fix (the merged
repairSlateChildrenload-time repair, "C"). That fix contained the crash; this PR closes the source of the corruption and adds a safety net, so empty links stop being created and can never crash the editor again.Background: Word
.docxfiles with a Table of Contents / cross-references contain hidden heading bookmarks. On import,mammothconverts each to an empty<a id="_Toc…"></a>. These were saved raw, then round-tripped by the@yoopta/link(de)serializer into<a href="" …></a>— which becomes an invalid inline link node that crashes the Slate editor when it sits at the start of a heading. One real slide carried 44 of these.Deliberately not included: a bulk DB migration ("D"). Existing affected slides already self-heal — on load via C, and on their next save via B — so no destructive backfill is needed.
Backend:
Frontend:
convertDocToHtmlnow runsstripEmptyAnchorson the mammoth output, so Word bookmark anchors are removed before the HTML is ever saved (doc-to-html.ts).formatHTMLString(the choke point every serialize/save flows through) now strips content-less anchors, so a corrupt link can never be persisted — this also closes the paste vector, which bypasses the load-time repair (formatHtmlString.tsx).stripEmptyAnchors(one source of truth for A and B); the load path continues to userepairSlateChildren(C).EditorErrorBoundaryaround the document editor. If any future unsanitized corruption throws during render, it degrades to a graceful in-place message + a Sentry report instead of the whole app hitting the global "Something went wrong" page. It resets on slide-switch so one bad slide doesn't blank out the rest.Related Issue
Type of Change
How Has This Been Tested?
stripEmptyAnchorsagainst the real production payload of the crashing slide (70 KB, 44 empty links): empty anchors 44 → 0, both genuine links preserved unchanged, all heading text intact ("From Script to Screen", "High Angle").<h1><a id="_Toc…"></a>Heading</h1>→<h1>Heading</h1>) and that a real<a href="…">text</a>is left byte-identical.tsc --noEmit(typecheck) passes clean.EditorErrorBoundarymirrors the existing, in-useYooptaEditorWrapperSafepattern (class boundary +Sentry.captureException).Checklist