Skip to content

fix(vite)!: replace buffer polyfill with data-uri-to-buffer shim#2054

Merged
Tobbe merged 4 commits into
mainfrom
tobbe-remove-node-polyfills-shim
Jul 7, 2026
Merged

fix(vite)!: replace buffer polyfill with data-uri-to-buffer shim#2054
Tobbe merged 4 commits into
mainfrom
tobbe-remove-node-polyfills-shim

Conversation

@Tobbe

@Tobbe Tobbe commented Jul 7, 2026

Copy link
Copy Markdown
Member

Remove vite-plugin-node-polyfills and the buffer package dependency. Instead of injecting a global Buffer polyfill, alias data-uri-to-buffer (used by stacktracey/get-source for inline source map parsing in the dev error page) to a tiny in-repo shim that returns a Uint8Array.

This avoids:

  • Complex CJS/ESM import.meta.url issues during Vite config loading
  • pnpm symlink resolution problems
  • Injected <script> tags in every dev page load
  • The full buffer polyfill dependency overhead

Remove vite-plugin-node-polyfills and the buffer package dependency.
Instead of injecting a global Buffer polyfill, alias data-uri-to-buffer
(used by stacktracey/get-source for inline source map parsing in the
dev error page) to a tiny in-repo shim that returns a Uint8Array.

This avoids:
- Complex CJS/ESM import.meta.url issues during Vite config loading
- pnpm symlink resolution problems
- Injected <script> tags in every dev page load
- The full buffer polyfill dependency overhead
@netlify

netlify Bot commented Jul 7, 2026

Copy link
Copy Markdown

Deploy Preview for cedarjs ready!

Name Link
🔨 Latest commit 635d9c2
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/6a4cb1961223b6000809d877
😎 Deploy Preview https://deploy-preview-2054--cedarjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@Tobbe Tobbe changed the title refactor(vite): replace buffer polyfill with data-uri-to-buffer shim fix(vite): replace buffer polyfill with data-uri-to-buffer shim Jul 7, 2026
@github-actions github-actions Bot added this to the next-release-patch milestone Jul 7, 2026
Tobbe added 2 commits July 7, 2026 09:32
The exclude:['util'] was needed because vite-plugin-node-polyfills
brought in node-util (Browserify's util polyfill), which would
incorrectly resolve instead of Node's built-in util, causing
TextEncoder to be missing. Since that dependency is now removed,
the workaround is no longer needed.
@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces the Vite Buffer polyfill with a focused data URI shim. The main changes are:

  • Removes direct buffer and vite-plugin-node-polyfills dependencies.
  • Adds a serve-only data-uri-to-buffer shim plugin.
  • Switches Cedar's Vite plugin exports and plugin list to the new shim.
  • Keeps the util optimizer exclusion for the RSC dev server.
  • Updates the project overview docs to name the new shim.

Confidence Score: 4/5

This is close, but the remaining dev-server resolution issue should be fixed before merging.

  • The new shim replaces the broad Buffer polyfill in the main Vite plugin path.
  • The RSC dev server has the intended util exclusion.
  • The sibling SSR dev server can still resolve util to the Browserify polyfill in Storybook workspaces.

packages/vite/src/devFeServer.ts

Important Files Changed

Filename Overview
packages/vite/src/plugins/vite-plugin-cedar-data-uri-shim.ts Adds the replacement Vite plugin that aliases data-uri-to-buffer to an inline shim during dev.
packages/vite/src/index.ts Replaces the node polyfill plugin export and usage with the new data URI shim plugin.
packages/vite/src/devFeServer.ts Keeps the util optimizer exclusion on the RSC dev server, but leaves the sibling SSR dev server without the same guard.
packages/vite/package.json Removes the direct Buffer and node polyfill dependencies from the Vite package.
yarn.lock Updates dependency metadata after removing the direct Vite package polyfill dependencies.
docs/implementation-docs/2026-03-26-cedarjs-project-overview.md Updates the Vite plugin overview to list the data URI shim instead of node polyfills.

Reviews (2): Last reviewed commit: "virtual module" | Re-trigger Greptile

Comment thread packages/vite/src/shim/data-uri-to-buffer.ts Outdated
Comment thread packages/vite/src/devFeServer.ts
@nx-cloud

nx-cloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 635d9c2

Command Status Duration Result
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 3s View ↗
nx run-many -t build ✅ Succeeded 3m 12s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-07-07 11:49:56 UTC

@Tobbe Tobbe changed the title fix(vite): replace buffer polyfill with data-uri-to-buffer shim fix(vite)!: replace buffer polyfill with data-uri-to-buffer shim Jul 7, 2026
Comment thread packages/vite/src/devFeServer.ts
@Tobbe Tobbe merged commit 870fb5f into main Jul 7, 2026
111 of 122 checks passed
@Tobbe Tobbe deleted the tobbe-remove-node-polyfills-shim branch July 7, 2026 12:09
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

The changes in this PR are now available on npm.

Try them out by running yarn cedar upgrade -t 5.0.0-canary.2598

Or try it in a new app with yarn dlx create-cedar-app@5.0.0-canary.2598

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.

1 participant