Skip to content

fix: replace Node.js Buffer APIs with browser-native alternatives#2028

Merged
caio-pizzol merged 8 commits intomainfrom
caio/sd-1916-fix-umd-bundle-crashing-with-buffer-is-not-defined
Feb 14, 2026
Merged

fix: replace Node.js Buffer APIs with browser-native alternatives#2028
caio-pizzol merged 8 commits intomainfrom
caio/sd-1916-fix-umd-bundle-crashing-with-buffer-is-not-defined

Conversation

@caio-pizzol
Copy link
Contributor

No description provided.

Reverts the vite.config.umd.js changes from 13fa579. Buffer usage
will be replaced with browser-native APIs instead of polyfilling.
Buffer.from, Buffer.isBuffer, and buffer-crc32 crash in browser/CDN
environments. Use Uint8Array, ArrayBuffer.isView, TextEncoder, and a
custom CRC32 table instead.
@linear
Copy link

linear bot commented Feb 14, 2026

…onfig

The generic `process` define wasn't replacing `process.env.NODE_ENV`
member accesses in the bundle, causing "process is not defined" at
runtime. Targeting the specific path fixes it and enables dead-code
elimination (~110KB smaller bundle).
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb320d65e9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Media values from #exportProcessMediaFiles are ArrayBuffers (via
getArrayBufferFromUrl), not base64 strings. Only call base64ToUint8Array
for string values to avoid crashing atob with binary input.
Copy link
Contributor

@andrii-harbour andrii-harbour left a comment

Choose a reason for hiding this comment

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

LGTM

- Remove vite-plugin-node-polyfills from UMD external/globals (build-time
  plugin, never imported at runtime)
- Reuse base64ToUint8Array from helpers.js in metafile-converter instead
  of duplicating the atob+charCodeAt loop
Verify output matches buffer-crc32 with known reference values to
prevent silent breakage of document fingerprinting.
Pin generateContentHash and generateIdentifierHash to exact expected
values instead of pattern matching. Add exportFromCollaborativeDocx
test covering both base64 string and ArrayBuffer media values.
@caio-pizzol caio-pizzol merged commit d6141ec into main Feb 14, 2026
3 checks passed
@caio-pizzol caio-pizzol deleted the caio/sd-1916-fix-umd-bundle-crashing-with-buffer-is-not-defined branch February 14, 2026 14:04
caio-pizzol added a commit that referenced this pull request Feb 14, 2026
)

* revert: remove nodePolyfills from UMD build

Reverts the vite.config.umd.js changes from 13fa579. Buffer usage
will be replaced with browser-native APIs instead of polyfilling.

* fix: replace Node.js Buffer APIs with browser-native alternatives

Buffer.from, Buffer.isBuffer, and buffer-crc32 crash in browser/CDN
environments. Use Uint8Array, ArrayBuffer.isView, TextEncoder, and a
custom CRC32 table instead.

* fix(build): replace process define with process.env.NODE_ENV in UMD config

The generic `process` define wasn't replacing `process.env.NODE_ENV`
member accesses in the bundle, causing "process is not defined" at
runtime. Targeting the specific path fixes it and enables dead-code
elimination (~110KB smaller bundle).

* fix: handle binary media values in collaborative export

Media values from #exportProcessMediaFiles are ArrayBuffers (via
getArrayBufferFromUrl), not base64 strings. Only call base64ToUint8Array
for string values to avoid crashing atob with binary input.

* refactor: remove dead externals config and consolidate base64 decode

- Remove vite-plugin-node-polyfills from UMD external/globals (build-time
  plugin, never imported at runtime)
- Reuse base64ToUint8Array from helpers.js in metafile-converter instead
  of duplicating the atob+charCodeAt loop

* test: add CRC32 parity tests for computeCrc32Hex

Verify output matches buffer-crc32 with known reference values to
prevent silent breakage of document fingerprinting.

* test: add base64ToUint8Array unit tests

* test: pin hash values and add mixed media export test

Pin generateContentHash and generateIdentifierHash to exact expected
values instead of pattern matching. Add exportFromCollaborativeDocx
test covering both base64 string and ArrayBuffer media values.
@superdoc-bot
Copy link

superdoc-bot bot commented Feb 14, 2026

🎉 This PR is included in superdoc v1.13.0-next.14

The release is available on GitHub release

superdoc-bot bot pushed a commit that referenced this pull request Feb 14, 2026
# [1.13.0](v1.12.0...v1.13.0) (2026-02-14)

### Bug Fixes

* anchor table overlaps text ([#1995](#1995)) ([fc05e29](fc05e29))
* collaboration cursor styles fix ([fd6db10](fd6db10))
* ensure we do not duplicate bubble text ([#1934](#1934)) ([c41cf9e](c41cf9e))
* ignore sdBlockId when pasting content ([#2010](#2010)) ([1b08572](1b08572))
* normalize bookmarks in tables ([#1892](#1892)) ([369b7e1](369b7e1))
* replace Node.js Buffer APIs with browser-native alternatives ([#2028](#2028)) ([b17774a](b17774a)), closes [#exportProcessMediaFiles](https://github.com/superdoc-dev/superdoc/issues/exportProcessMediaFiles)
* use correct template syntax for GitHub release URL in PR comments ([9d1bca2](9d1bca2))

### Features

* enabled telemetry by default and added documentation ([#2001](#2001)) ([8598ef7](8598ef7))
* enhance telemetry handling for sub-editors ([#2017](#2017)) ([37bc030](37bc030))
* update telemetry configuration to prioritize root licenseKey ([#2016](#2016)) ([3b4ff6b](3b4ff6b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants