Skip to content

fix(playground): make svelte work for prettier#3697

Merged
dyc3 merged 1 commit intomainfrom
dyc3/fix-prettier-svelte
Dec 28, 2025
Merged

fix(playground): make svelte work for prettier#3697
dyc3 merged 1 commit intomainfrom
dyc3/fix-prettier-svelte

Conversation

@dyc3
Copy link
Contributor

@dyc3 dyc3 commented Dec 20, 2025

Summary

I finally figured out why the svelte prettier plugin wasn't working. This PR fixes it, and makes it a bit easier to get log output from the workers.

@netlify
Copy link

netlify bot commented Dec 20, 2025

Deploy Preview for biomejs ready!

Name Link
🔨 Latest commit e2bffcc
🔍 Latest deploy log https://app.netlify.com/projects/biomejs/deploys/69514704d86db0000879dc7e
😎 Deploy Preview https://deploy-preview-3697--biomejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 20, 2025

Walkthrough

package.json adds svelte (^5.46.0) and bumps prettier-plugin-svelte to 3.4.1. Both Biome and Prettier workers now capture console methods and forward structured log messages to the main thread via postMessage. prettierWorker switches imports to prettier/standalone and prettier/plugins/babel, changes embeddedLanguageFormatting to "auto", adds svelteIndentScriptAndStyle, and preserves inclusion of Svelte alongside existing Prettier plugins. PlaygroundLoader handlers are extended to process incoming log messages with level-aware routing.

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarises the main fix: enabling Svelte support in Prettier for the playground, which aligns with the changeset's primary objective.
Description check ✅ Passed The description is related to the changeset, explaining the motivation (Svelte plugin fix) and the secondary benefit (improved worker logging), both of which are present in the changes.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dyc3/fix-prettier-svelte

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b50f67 and e2bffcc.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Redirect rules - biomejs
  • GitHub Check: Header rules - biomejs
  • GitHub Check: test
  • GitHub Check: Pages changed - biomejs

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/playground/PlaygroundLoader.tsx (1)

95-117: Log handlers implemented correctly.

The message handling for cross-context logging from both workers is sound and integrates well with the worker-side logging bridges.

The log handling logic is duplicated between the two workers. Consider extracting a helper function to reduce duplication:

🔎 Optional refactor to reduce duplication
+function createLogHandler(workerName: string) {
+  return (event: MessageEvent) => {
+    const { level, message } = event.data as {
+      level: "log" | "info" | "warn" | "error";
+      message: unknown[];
+    };
+    const prefix = `[${workerName}]`;
+    switch (level) {
+      case "log":
+        console.log(prefix, ...message);
+        break;
+      case "info":
+        console.info(prefix, ...message);
+        break;
+      case "warn":
+        console.warn(prefix, ...message);
+        break;
+      case "error":
+        console.error(prefix, ...message);
+        break;
+      default:
+        console.log(prefix, ...message);
+    }
+  };
+}
+
 workerRef.current.addEventListener("message", (event) => {
   switch (event.data.type) {
     // ... existing cases ...
     case "log": {
-      const { level, message } = event.data as {
-        level: "log" | "info" | "warn" | "error";
-        message: unknown[];
-      };
-      switch (level) {
-        case "log":
-          console.log("[Biome worker]", ...message);
-          break;
-        case "info":
-          console.info("[Biome worker]", ...message);
-          break;
-        case "warn":
-          console.warn("[Biome worker]", ...message);
-          break;
-        case "error":
-          console.error("[Biome worker]", ...message);
-          break;
-        default:
-          console.log("[Biome worker]", ...message);
-      }
+      createLogHandler("Biome worker")(event);
       break;
     }

Also applies to: 141-163

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86bd329 and 6e21027.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • package.json (2 hunks)
  • src/playground/PlaygroundLoader.tsx (2 hunks)
  • src/playground/workers/biomeWorker.ts (1 hunks)
  • src/playground/workers/prettierWorker.ts (4 hunks)
🧰 Additional context used
🪛 GitHub Actions: Integrate
src/playground/workers/biomeWorker.ts

[error] 1-1: Cannot find module '@biomejs/wasm-web' or its corresponding type declarations.

src/playground/PlaygroundLoader.tsx

[error] 5-5: Cannot find module '@biomejs/wasm-web' or its corresponding type declarations.

src/playground/workers/prettierWorker.ts

[error] 1-1: Cannot find module '@biomejs/wasm-web' or its corresponding type declarations.

🪛 GitHub Actions: Playwright Tests
src/playground/PlaygroundLoader.tsx

[error] 1-1: Build failed: Failed to resolve entry for package '@biomejs/wasm-web'. The package may have incorrect main/module/exports specified in its package.json.

🔇 Additional comments (5)
src/playground/workers/biomeWorker.ts (1)

37-77: Excellent console bridging implementation.

The logging bridge properly captures console output, serialises it defensively (with JSON.stringify and String() fallback), and forwards structured messages to the main thread whilst preserving the original console behaviour.

src/playground/workers/prettierWorker.ts (3)

40-80: Console bridging matches biomeWorker implementation.

The logging bridge is implemented consistently with the Biome worker, which is excellent for maintainability.


193-195: Key fix for Svelte formatting.

Changing embeddedLanguageFormatting to "auto" and adding svelteIndentScriptAndStyle are the crucial changes that enable proper Svelte formatting. Well done!


2-2: Imports are already correct for Prettier 3.7.4.

The import path "prettier/plugins/babel" aligns with the Prettier 3.0+ migration, which replaced the earlier "prettier/parser-babel" naming convention. Prettier 3.0 introduced standalone.mjs in place of the earlier esm/standalone.mjs, and the correct Node.js import for plugins is prettier/plugins/graphql (and similarly for other plugins). The current imports require no changes.

package.json (1)

68-68: Dependency updates sound solid.

The prettier-plugin-svelte patch to 3.4.1 (latest version) and addition of svelte 5.46.0 (latest version) align with the PR's goal to fix Svelte formatting support. No security advisories apply to these versions.

"starlight-blog": "0.25.2",
"starlight-changelogs": "0.2.3",
"starlight-links-validator": "0.18.0",
"svelte": "^5.46.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

needed because the plugin uses the svelte compiler to parse svelte

embeddedLanguageFormatting: "off",
embeddedLanguageFormatting: "auto",
vueIndentScriptAndStyle: options.vueIndentScriptAndStyle,
svelteIndentScriptAndStyle: options.vueIndentScriptAndStyle,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

svelte has it's own option for this

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/playground/workers/biomeWorker.ts (1)

62-77: LGTM! Consider a helper to reduce duplication.

The console overrides work correctly but follow a repetitive pattern. A small helper could tidy this up if you're ever back here.

Optional refactor to reduce duplication
+type LogLevel = "log" | "info" | "warn" | "error";
+
+function wrapConsoleMethod(level: LogLevel) {
+	const original = originalConsole[level];
+	console[level] = (...args: unknown[]) => {
+		postLog(level, args);
+		original(...args);
+	};
+}
+
-console.log = (...args: unknown[]) => {
-	postLog("log", args);
-	originalConsole.log(...args);
-};
-console.info = (...args: unknown[]) => {
-	postLog("info", args);
-	originalConsole.info(...args);
-};
-console.warn = (...args: unknown[]) => {
-	postLog("warn", args);
-	originalConsole.warn(...args);
-};
-console.error = (...args: unknown[]) => {
-	postLog("error", args);
-	originalConsole.error(...args);
-};
+(["log", "info", "warn", "error"] as const).forEach(wrapConsoleMethod);
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6e21027 and 1b50f67.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • package.json
  • src/playground/PlaygroundLoader.tsx
  • src/playground/workers/biomeWorker.ts
  • src/playground/workers/prettierWorker.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • package.json
  • src/playground/PlaygroundLoader.tsx
  • src/playground/workers/prettierWorker.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Redirect rules - biomejs
  • GitHub Check: Header rules - biomejs
  • GitHub Check: Pages changed - biomejs
🔇 Additional comments (2)
src/playground/workers/biomeWorker.ts (2)

37-42: LGTM! Preserving original console methods.

Good practice to stash the originals before wrapping.


44-60: LGTM! Robust serialisation with appropriate error handling.

The nested try-catch structure ensures logging failures never break the worker—exactly what you want from infrastructure code.

@dyc3 dyc3 force-pushed the dyc3/fix-prettier-svelte branch from 1b50f67 to e2bffcc Compare December 28, 2025 15:04
@dyc3 dyc3 requested review from a team December 28, 2025 15:04
@dyc3 dyc3 merged commit 923f39e into main Dec 28, 2025
9 checks passed
@dyc3 dyc3 deleted the dyc3/fix-prettier-svelte branch December 28, 2025 16:09
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.

2 participants