Fix DataCloneError with Prettier plugins containing functions in PNPM projects#3916
Draft
Fix DataCloneError with Prettier plugins containing functions in PNPM projects#3916
Conversation
Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
Member
|
@Copolit we need to have a test case for this in our tests to validate the fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prettier plugins (e.g., prettier-plugin-sh) can include functions in their configuration that cannot be serialized when passed across worker boundaries, causing DataCloneError. If
getSupportInfofails, the extension crashes onundefined.forEach.Changes
sanitizePlugin()function: Recursively strips function properties from plugin objects before passing to Prettier APIs, preserving all serializable configurationgetSupportInfocalls: Wrapped both invocations in try-catch with empty array fallbacks, allowing extension to continue with default language support||to??for precise null-safety semanticsWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://storage.googleapis.com/chrome-for-testing-public/143.0.7499.4/linux64/chrome-headless-shell-linux64.zip/usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/prettier-vscode/prettier-vscode/node_modules/playwright-core/lib/server/registry/oopDownloadBrowserMain.js(http block)https://storage.googleapis.com/chrome-for-testing-public/143.0.7499.4/linux64/chrome-linux64.zip/usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/prettier-vscode/prettier-vscode/node_modules/playwright-core/lib/server/registry/oopDownloadBrowserMain.js(http block)update.code.visualstudio.com/usr/local/bin/node node /home/REDACTED/work/prettier-vscode/prettier-vscode/node_modules/.bin/vscode-test --grep plugins -150�� test && node scripts/install-fixtures.mjs(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>DOMError when in PNPM package and using prettier plugin</issue_title>
<issue_description>### Preflight Checklist
Issue Summary
Prettier VSCode extension fails with an exception when run in a PNPM project, and prettier config has at least one plugin.
This is a follow up on #3036 and #3037 which were closed without a fix
Reproduction Repository
https://github.com/maxpatiiuk/pnpm-prettier-vscode
Steps to Reproduce
Clone repository
git clone https://github.com/maxpatiiuk/pnpm-prettier-vscode cd pnpm-prettier-vscodeRun PNPM install:
Open VSCode and go to the "Output" tab.
Open ./README.md then switch to ./test.ts.
See exception in the console.
Also, file is not formatted on save.
Comment out the plugin in prettier.config.js and restart vscode - the error is gone.
Expected Behavior
No exception
Actual Behavior
Code is not reformated. VSCode Output for Prettier plugin contains:
It seems to be trying to serialize an Error object to pass it from the worker to the main thread and fails.
When I resolve that bug by updating the extension source code to wrap the error object in a
String()to make it serializable, I get the actual cause:Which happens here in the source code:
prettier-vscode/src/PrettierEditService.ts
Line 398 in 49528d4
Operating System
macOS
VS Code Version
1.108.0
Prettier Extension Version
11.0.2
Prettier Version
3.8.0
Prettier Extension Logs
...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.