Skip to content

fix(Markdown):修复关闭编辑弹窗时销毁的问题 - #1092

Open
Tony-ST0754 wants to merge 2 commits into
masterfrom
Markdown-DialogClose
Open

fix(Markdown):修复关闭编辑弹窗时销毁的问题#1092
Tony-ST0754 wants to merge 2 commits into
masterfrom
Markdown-DialogClose

Conversation

@Tony-ST0754

@Tony-ST0754 Tony-ST0754 commented Aug 9, 2026

Copy link
Copy Markdown

fix:修复Markdown组件在编辑弹窗中,关闭弹窗时浏览器控制台报错找不到节点元素的问题

Link issues

fixes #1091

问题描述 / Problem Description

当组件在弹窗中使用时,由于弹窗先销毁,然后再销毁组件,导致组件在销毁时找不到对应的元素

解决方案 / Solution

在组件初始化时,将组件的销毁与弹窗的销毁绑定

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Bug Fixes:

  • Prevent console errors caused by the Markdown component trying to dispose after its DOM element has already been destroyed when used inside a modal dialog.

fix:修复Markdown组件在编辑弹窗中,关闭弹窗时浏览器控制台报错找不到节点元素的问题
@bb-auto

bb-auto Bot commented Aug 9, 2026

Copy link
Copy Markdown

Thanks for your PR, @Tony-ST0754. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@sourcery-ai

sourcery-ai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Binds the Markdown editor’s lifecycle to its containing Bootstrap modal so that the editor is disposed safely when the modal closes, preventing console errors about missing DOM nodes.

Sequence diagram for Markdown editor disposal bound to Bootstrap modal lifecycle

sequenceDiagram
    actor User
    participant BootstrapModal as BootstrapModal
    participant MarkdownEditor as MarkdownEditor
    participant Data as DataStore

    User->>BootstrapModal: close()
    BootstrapModal-->>BootstrapModal: emit hide.bs.modal
    BootstrapModal->>MarkdownEditor: md._modalHideHandler()
    MarkdownEditor->>MarkdownEditor: disposeEditor(id)
    MarkdownEditor->>Data: Data.get(id)
    MarkdownEditor->>BootstrapModal: md._modal.removeEventListener(hide.bs.modal, md._modalHideHandler)
    MarkdownEditor->>Data: Data.remove(id)
    MarkdownEditor->>MarkdownEditor: md._editor.off(blur)
    MarkdownEditor->>MarkdownEditor: md._editor.destroy()
Loading

File-Level Changes

Change Details Files
Bind Markdown editor disposal to Bootstrap modal hide events and centralize cleanup logic to avoid accessing destroyed DOM nodes.
  • Capture the closest Bootstrap modal element for the Markdown editor during initialization and register a hide.bs.modal event handler that disposes the editor when the modal closes.
  • Refactor disposal logic into a new disposeEditor helper reused by both the public dispose function and the modal hide event handler.
  • On disposal, remove the registered modal hide event listener before cleaning up the editor and its event handlers to prevent leaks or duplicate disposal attempts.
src/components/BootstrapBlazor.Markdown/Components/Markdown/Markdown.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#1091 Fix the Markdown component error that occurs in the browser console when the component is used inside a modal and the modal is closed, ensuring it disposes cleanly without accessing missing DOM elements.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto
bb-auto Bot requested a review from ArgoZhang August 9, 2026 08:05
@bb-auto bb-auto Bot added the bug Something isn't working label Aug 9, 2026
@bb-auto bb-auto Bot added this to the v10.0.0 milestone Aug 9, 2026

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

Hey - I've left some high level feedback:

  • disposeEditor assumes Data.get(id) returns a valid object; consider adding null/undefined guards around md and md._editor to avoid errors if dispose is called multiple times (e.g., both from the modal hide handler and the component lifecycle).
  • The modal event listener is attached to 'hide.bs.modal', which fires before the modal is fully hidden; verify whether binding to 'hidden.bs.modal' would better align with the timing of DOM removal and avoid potential race conditions with other modal teardown logic.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- disposeEditor assumes Data.get(id) returns a valid object; consider adding null/undefined guards around md and md._editor to avoid errors if dispose is called multiple times (e.g., both from the modal hide handler and the component lifecycle).
- The modal event listener is attached to 'hide.bs.modal', which fires before the modal is fully hidden; verify whether binding to 'hidden.bs.modal' would better align with the timing of DOM removal and avoid potential race conditions with other modal teardown logic.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Tony-ST0754 Tony-ST0754 changed the title (fix):修复Markdown组件在编辑弹窗中,关闭弹窗时浏览器控制台报错找不到节点元素的问题 fix(Markdown):修复Markdown组件在编辑弹窗中,关闭弹窗时浏览器控制台报错找不到节点元素的问题 Aug 9, 2026
@Tony-ST0754 Tony-ST0754 changed the title fix(Markdown):修复Markdown组件在编辑弹窗中,关闭弹窗时浏览器控制台报错找不到节点元素的问题 fix(Markdown):修复编辑弹窗中销毁时的问题 Aug 9, 2026
@Tony-ST0754 Tony-ST0754 changed the title fix(Markdown):修复编辑弹窗中销毁时的问题 fix(Markdown):修复关闭编辑弹窗时销毁的问题 Aug 9, 2026
chore:补允安全防御
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(Markdown): 修正组件在弹窗中使用时,关闭弹窗后浏览器控制台报错的问题

2 participants