Skip to content

[WC-3431]: Doc Viewer Checkbox Fix#2262

Merged
samuelreichert merged 8 commits into
mainfrom
fix/WC-3431-doc-viewer-checkbox-fix
Jun 19, 2026
Merged

[WC-3431]: Doc Viewer Checkbox Fix#2262
samuelreichert merged 8 commits into
mainfrom
fix/WC-3431-doc-viewer-checkbox-fix

Conversation

@samuelreichert

Copy link
Copy Markdown
Contributor

Pull request type

Bug fix (non-breaking change which fixes an issue)


Description

Fix PDF standard font rendering in Document Viewer

Problem: PDFs containing glyphs from ZapfDingbats (e.g. checkmarks generated by .NET PDF libraries) rendered as blank rectangles in Document Viewer. The browser's native PDF viewer displayed them correctly.

Root cause: standardFontDataUrl and cMapUrl were relative paths. The PDF.js worker is loaded from //unpkg.com (cross-origin), so fetch() in the worker context has no document origin to resolve relative URLs against — throwing TypeError: Failed to parse URL.

Fix: Prepend window.location.origin to both URLs, making them absolute and resolvable from any worker origin.

Tested with:

  • Customer W9 PDF (C corporation checkbox now shows as checked ✓)
  • Plain PDF with no form fields (no regression ✓)

@samuelreichert samuelreichert requested a review from a team as a code owner June 12, 2026 12:14
Comment thread openspec/changes/archive/2026-06-12-document-viewer-render-forms-fix/design.md Outdated
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@samuelreichert samuelreichert requested a review from r0b1n June 16, 2026 13:10
@github-actions

This comment has been minimized.

r0b1n
r0b1n previously approved these changes Jun 16, 2026
samuelreichert and others added 7 commits June 18, 2026 15:13
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use mx.appUrl (with window.location.origin fallback) for cMapUrl and
standardFontDataUrl so the PDF.js worker can resolve font and cmap
resources when loaded from a cross-origin URL.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@samuelreichert samuelreichert force-pushed the fix/WC-3431-doc-viewer-checkbox-fix branch from 863b072 to bd769e1 Compare June 18, 2026 13:13
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

AI Code Review

⚠️ Approved with suggestions — low-severity items only, safe to merge


What was reviewed

File Change
packages/pluggableWidgets/document-viewer-web/src/components/PDFViewer.tsx Core fix: absolute origin prepended to cMapUrl and standardFontDataUrl
packages/pluggableWidgets/document-viewer-web/typings/global.d.ts New: Window.mx.appUrl type declaration
packages/pluggableWidgets/document-viewer-web/typings/modules.d.ts New: *.css module declaration
packages/pluggableWidgets/document-viewer-web/src/components/__tests__/PDFViewer.spec.tsx New: comprehensive unit tests for PDFViewer
packages/pluggableWidgets/document-viewer-web/src/components/__tests__/BaseViewer.spec.tsx New: unit tests for BaseViewer/BaseControlViewer
packages/pluggableWidgets/document-viewer-web/src/utils/__tests__/dimension.spec.ts New: unit tests for constructWrapperStyle
packages/pluggableWidgets/document-viewer-web/src/utils/__tests__/helpers.spec.ts New: unit tests for downloadFile
packages/pluggableWidgets/document-viewer-web/src/utils/__tests__/useZoomScale.spec.ts New: unit tests for useZoomScale hook
packages/pluggableWidgets/document-viewer-web/package.json test script now runs pluggable-widgets-tools test:unit:web
packages/pluggableWidgets/document-viewer-web/CHANGELOG.md [Unreleased] Fixed entry added
openspec/changes/archive/2026-06-12-document-viewer-render-forms-fix/ OpenSpec archived change artefacts

Skipped (out of scope): dist/, pnpm-lock.yaml


Findings

⚠️ Low — "Fit to width" button has wrong disabled condition

File: packages/pluggableWidgets/document-viewer-web/src/components/PDFViewer.tsx line 186
Problem: The "Fit to width" / reset button is disabled when zoomLevel >= 10, which is the zoom-in upper bound. The reset button should only be disabled when the zoom is already at the default level (1), or not disabled at all — it's never harmful to reset.
Fix:

<button
    onClick={reset}
    disabled={zoomLevel === 1}
    className="icons icon-FitToWidth btn btn-icon-only"
    aria-label={"Fit to width"}
    title={"Fit to width"}
></button>

⚠️ Low — window.mx type is narrower than the rest of the monorepo

File: packages/pluggableWidgets/document-viewer-web/typings/global.d.ts
Problem: Other packages (e.g. google-tag-web) declare a richer Window.mx type (mx.session, mx.ui, etc.). The new declaration only adds mx?: { appUrl?: string }. Because TypeScript merges interface declarations, this is safe at compile time, but the minimal shape is silently inconsistent with the broader platform contract and could mislead future readers.
Note: If there is ever a shared @mendix/widget-plugin-platform-types package this should move there. For now, widening to include at least session (as the other widgets do) would be consistent. Not blocking — the existing pattern of per-package declarations is already in use across the monorepo.


⚠️ Low — Module-scope window access is not guarded at module evaluation time

File: packages/pluggableWidgets/document-viewer-web/src/components/PDFViewer.tsx line 11
Problem: window.mx?.appUrl is read at module-scope (outside any function/hook). This is generally safe in a browser context, but if the module is ever loaded in a Node-based environment (SSR, test, tooling) window will be undefined and throw. The design doc acknowledges this risk. Currently tests rely on jsdom's window, so they pass, but the lack of a guard is a latent footgun.
Note: A simple guard: const origin = typeof window !== "undefined" ? (window.mx?.appUrl ?? window.location.origin).replace(/\/$/, "") : "" would make it robust. Low priority because Mendix pluggable widgets are browser-only.


Positives

  • The root-cause analysis is precise: relative URLs cannot be resolved from a cross-origin worker thread — the fix directly addresses this rather than working around it (useWorkerFetch: false was correctly rejected).
  • Using window.mx.appUrl as the primary source correctly handles Mendix apps served from a subpath, which window.location.origin alone would not cover.
  • The trailing-slash strip (replace(/\/$/, "")) prevents double-slash artifacts; and standardFontDataUrl now correctly ends with a trailing slash, matching the cMap URL convention.
  • jest.resetModules() + dynamic require() to re-evaluate the module-scope origin constant between test cases is an elegant and correct solution to a real testing challenge — well documented in the test comment.
  • Test coverage is extensive: all four window.mx states, worker URL variants, pagination edge cases, zoom bounds, and keyboard input filtering are all covered.
  • The test script was changed from echo 'FIXME: Add unit tests' to the real test runner — closing a long-standing gap.
  • CHANGELOG entry is user-focused and matches the Keep a Changelog format.

@samuelreichert samuelreichert merged commit f53d47d into main Jun 19, 2026
13 of 14 checks passed
@samuelreichert samuelreichert deleted the fix/WC-3431-doc-viewer-checkbox-fix branch June 19, 2026 07:57
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.

3 participants