Skip to content

fix(Editor): upload image not work#851

Merged
ArgoZhang merged 2 commits intomasterfrom
fix-editor
Dec 21, 2025
Merged

fix(Editor): upload image not work#851
ArgoZhang merged 2 commits intomasterfrom
fix-editor

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Dec 21, 2025

Link issues

fixes #850

Summary By Copilot

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:

  • Fix image upload and other SummerNote events not firing by correctly resolving and binding per-editor callback handlers only when available.

Copilot AI review requested due to automatic review settings December 21, 2025 11:13
@bb-auto bb-auto Bot added the enhancement New feature or request label Dec 21, 2025
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Dec 21, 2025
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Dec 21, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts SummerNote editor callback wiring so event handlers are only registered when corresponding callbacks exist, fixing the image upload event handling issue.

Sequence diagram for SummerNote editor ImageUpload callback handling

sequenceDiagram
    actor User
    participant BrowserEditor as EditorComponent
    participant SummerNote as SummerNoteEditor
    participant Callbacks as CallbackRegistry
    participant Handler as ImageUploadHandler

    User->>BrowserEditor: Select image for upload
    BrowserEditor->>SummerNote: Trigger ImageUpload with option.callbacks
    SummerNote-->>SummerNote: Call option.callbacks.onImageUpload(fileList)
    SummerNote->>Handler: onImageUpload(fileList)
    Handler-->>SummerNote: Process upload
    SummerNote-->>BrowserEditor: Update editor content
    BrowserEditor-->>User: Render uploaded image
Loading

Flow diagram for reloadCallbacks option callback wiring

flowchart TD
    A["reloadCallbacks(id, option)"] --> B["Read window.BootstrapBlazor.SummerNote.callbacks"]
    B --> C["Find cb where cb.id === id"]
    C -->|cb not found| D["Do not register any callbacks"]
    C -->|cb found| E["Iterate events: Blur, BlurCodeview, Change, ... , Scroll"]
    E --> F["For each event get method cb[onEvent]"]
    F -->|method is undefined| G["Skip this event"]
    F -->|method exists| H["Assign option.callbacks[onEvent] = wrapper calling method.apply"]
    H --> I["Next event"]
    G --> I
    I -->|all events processed| J["Callbacks registered only for existing methods"]
Loading

File-Level Changes

Change Details Files
Guard callback registration in the SummerNote editor so events are only wired when a matching callback object exists for the given editor id, and only for events that have handlers.
  • Resolve the callbacks collection and the callback entry for the current editor id once before iterating over events.
  • Check for existence of the callback entry (cb) before registering any event callbacks.
  • For each event in the predefined events list, look up the corresponding method on the callback entry and only assign option.callbacks handlers when that method exists.
  • Replace the previous generic dispatcher that assumed a callback entry existed with a direct call to the resolved method, preserving the original invocation context and arguments.
src/components/BootstrapBlazor.SummerNote/Components/Editor/Editor.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#850 Fix the Editor image upload functionality so that image upload callbacks are correctly wired and image uploads work as expected.

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

@ArgoZhang ArgoZhang merged commit 7710f34 into master Dec 21, 2025
5 of 6 checks passed
@ArgoZhang ArgoZhang deleted the fix-editor branch December 21, 2025 11:14
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

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:

  • By resolving cb once and only wiring callbacks when it exists, the change removes the previous ability to lazily register callbacks after init; consider whether callbacks need to be discoverable dynamically at call time as before.
  • Previously, all SummerNote events were wired to a no-op wrapper even if no handler was defined; now missing handlers result in no callback being set at all—if the editor or plugins rely on the presence of a callback key, you may want to preserve the wrapper and just guard inside it.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- By resolving `cb` once and only wiring callbacks when it exists, the change removes the previous ability to lazily register callbacks after `init`; consider whether callbacks need to be discoverable dynamically at call time as before.
- Previously, all SummerNote events were wired to a no-op wrapper even if no handler was defined; now missing handlers result in no callback being set at all—if the editor or plugins rely on the presence of a callback key, you may want to preserve the wrapper and just guard inside it.

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.

Copy link
Copy Markdown

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 fixes a bug where image upload functionality in the Editor component was not working correctly. The issue was caused by empty callback wrappers being set up for all events, which interfered with the onImageUpload callback.

Key changes:

  • Refactored the reloadCallbacks function to only create callback wrappers for events that actually have registered callbacks
  • Bumped the package version to 10.0.1 (patch version for bug fix)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/components/BootstrapBlazor.SummerNote/Components/Editor/Editor.razor.js Refactored callback registration logic to prevent empty wrappers from interfering with image upload functionality
src/components/BootstrapBlazor.SummerNote/BootstrapBlazor.SummerNote.csproj Bumped version to 10.0.1 for this bug fix release

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(Editor): upload image not work

2 participants