Skip to content

feat(SignaturePad): fingerprint CSS asset - #1244

Merged
ArgoZhang merged 6 commits into
masterfrom
dev-SignaturePad
Oct 24, 2026
Merged

ArgoZhang merged 6 commits into
masterfrom
dev-SignaturePad

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Link issues

fixes #1243

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

Improve SignaturePad asset loading, resizing behavior, and resource cleanup.

New Features:

  • Add fingerprinted CSS asset resolution for the SignaturePad component across supported .NET versions.

Bug Fixes:

  • Preserve signature content when the signing area is resized by scaling existing points to the new dimensions.
  • Improve download cleanup and observer disposal for SignaturePad resources.

Enhancements:

  • Modernize SignaturePad API documentation with bilingual XML descriptions.

Build:

  • Update SignaturePad project packaging to support the CSS asset changes.

@sourcery-ai

sourcery-ai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR fingerprints the SignaturePad CSS asset by resolving its packaged URL in Razor and injecting it into JavaScript, while also revising canvas resize handling to retain and scale existing strokes and tightening download and observer cleanup.

Sequence diagram for fingerprinted SignaturePad initialization

sequenceDiagram
    participant SignaturePad as SignaturePad Razor
    participant JS as SignaturePad JavaScript
    participant Assets as Asset resolver
    participant DOM as Browser DOM

    SignaturePad->>Assets: Resolve Assets[StylePath]
    Assets-->>SignaturePad: Return fingerprinted StyleUrl
    SignaturePad->>JS: init(id, invoke, alertText, backgroundColor, styleUrl)
    JS->>DOM: addLink(styleUrl)
    JS->>DOM: Create SignaturePad and observe element resize
Loading

Sequence diagram for SignaturePad disposal cleanup

sequenceDiagram
    participant Component as SignaturePad component
    participant JS as SignaturePad JavaScript
    participant Data as Data registry
    participant Observer as ResizeObserver

    Component->>JS: dispose(id)
    JS->>Data: Data.get(id)
    Data-->>JS: Return observer
    JS->>Observer: disconnect()
    JS->>Data: Data.remove(id)
Loading

Flow diagram for preserving SignaturePad strokes during resize

flowchart TD
    A["ResizeObserver detects size change"] --> B["Capture signaturePad.toData()"]
    B --> C["Resize canvas for devicePixelRatio"]
    C --> D{"Existing stroke data?"}
    D -->|Yes| E["Scale stroke points"]
    E --> F["signaturePad.fromData(data)"]
    D -->|No| G["signaturePad.clear()"]
Loading

File-Level Changes

Change Details Files
Makes the SignaturePad stylesheet URL compatible with fingerprinted/static-web-asset packaging and passes it into JavaScript initialization.
  • Adds framework-conditional asset URL resolution using the generated asset manifest on .NET 9+.
  • Changes initialization to load the supplied stylesheet URL instead of a hard-coded path.
  • Updates project packaging metadata for the CSS asset.
src/components/BootstrapBlazor.SignaturePad/BootstrapBlazor.SignaturePad.csproj
src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.cs
src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js
Preserves signature strokes when the observed container is resized while improving lifecycle and download cleanup.
  • Tracks prior dimensions and rescales stored stroke points after canvas resizing.
  • Continues to clear the pad when no stroke data exists and disposes the ResizeObserver through the stored observer reference.
  • Defers object-URL revocation and removes the temporary download link.
src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#1243 Load the SignaturePad CSS asset using a fingerprinted URL so changes to the asset can be reflected without stale caching. ✅

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 added the enhancement New feature or request label Oct 24, 2026
@bb-auto bb-auto Bot added this to the v10.0.0 milestone Oct 24, 2026
bb-auto[bot]
bb-auto Bot previously approved these changes Oct 24, 2026

@bb-auto bb-auto 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.

Auto approved by bb-auto

@bb-auto bb-auto 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.

Auto approved by bb-auto

@ArgoZhang
ArgoZhang merged commit 31f86b2 into master Oct 24, 2026
3 checks passed
@ArgoZhang
ArgoZhang deleted the dev-SignaturePad branch October 24, 2026 01:17

@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 found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js" line_range="30-31" />
<code_context>
+        var width = canvas.parentElement.offsetWidth;
+        var height = canvas.parentElement.offsetHeight;
+        var data = signaturePad.toData();
+        var scaleX = previousWidth > 0 ? width / previousWidth : 1;
+        var scaleY = previousHeight > 0 ? height / previousHeight : 1;

-        // This part causes the canvas to be cleared
</code_context>
<issue_to_address>
**Resizing collapses saved signatures**

When the pad is hidden or collapsed until its parent reports a zero width or height, then expands, `resizeCanvas` scales saved points to zero on a collapsed axis or records zero as the previous dimension; on expansion, the fallback scale of 1 cannot restore the original coordinates, so the signature appears collapsed, misplaced, clipped, or undersized.

Ignore zero-dimension resize measurements and preserve the last nonzero dimensions and saved point coordinates until the pad has nonzero dimensions again.

Also at `src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js:32`.
</issue_to_address>

### Comment 2
<location path="src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js" line_range="41-49" />
<code_context>
+        previousHeight = height;
+
+        if (data.length > 0) {
+            signaturePad.fromData(data.map(group => ({
+                ...group,
+                points: group.points.map(point => ({
+                    ...point,
+                    x: point.x * scaleX,
+                    y: point.y * scaleY
+                }))
+            })));
+        }
+        else {
+            signaturePad.clear();
</code_context>
<issue_to_address>
**Resized signatures cannot be saved**

When a signature is present and the canvas is resized, `signaturePad.fromData()` clears the pad before redrawing and leaves its `isEmpty()` flag set, so the save handlers treat the visible signature as empty and refuse to export it.

Restore the non-empty state after redrawing the signature, or use a redraw path that preserves the pad’s `isEmpty()` state.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines +30 to +31
var scaleX = previousWidth > 0 ? width / previousWidth : 1;
var scaleY = previousHeight > 0 ? height / previousHeight : 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Resizing collapses saved signatures

When the pad is hidden or collapsed until its parent reports a zero width or height, then expands, resizeCanvas scales saved points to zero on a collapsed axis or records zero as the previous dimension; on expansion, the fallback scale of 1 cannot restore the original coordinates, so the signature appears collapsed, misplaced, clipped, or undersized.

Ignore zero-dimension resize measurements and preserve the last nonzero dimensions and saved point coordinates until the pad has nonzero dimensions again.

Also at src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js:32.

Prompt for AI agents
In `src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js` at lines 30-31:

**Resizing collapses saved signatures**

When the pad is hidden or collapsed until its parent reports a zero width or height, then expands, `resizeCanvas` scales saved points to zero on a collapsed axis or records zero as the previous dimension; on expansion, the fallback scale of 1 cannot restore the original coordinates, so the signature appears collapsed, misplaced, clipped, or undersized.

Ignore zero-dimension resize measurements and preserve the last nonzero dimensions and saved point coordinates until the pad has nonzero dimensions again.

Also at `src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js:32`.

Comment on lines +41 to +49
signaturePad.fromData(data.map(group => ({
...group,
points: group.points.map(point => ({
...point,
x: point.x * scaleX,
y: point.y * scaleY
}))
})));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Resized signatures cannot be saved

When a signature is present and the canvas is resized, signaturePad.fromData() clears the pad before redrawing and leaves its isEmpty() flag set, so the save handlers treat the visible signature as empty and refuse to export it.

Restore the non-empty state after redrawing the signature, or use a redraw path that preserves the pad’s isEmpty() state.

Prompt for AI agents
In `src/components/BootstrapBlazor.SignaturePad/SignaturePad.razor.js` at lines 41-49:

**Resized signatures cannot be saved**

When a signature is present and the canvas is resized, `signaturePad.fromData()` clears the pad before redrawing and leaves its `isEmpty()` flag set, so the save handlers treat the visible signature as empty and refuse to export it.

Restore the non-empty state after redrawing the signature, or use a redraw path that preserves the pad’s `isEmpty()` state.

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.

feat(SignaturePad): fingerprint CSS asset

1 participant