From 69fe5541422fdfee0f4e496cd7c7296a892cd108 Mon Sep 17 00:00:00 2001 From: divybot Date: Sat, 30 May 2026 03:16:10 +0000 Subject: [PATCH 1/2] fix(fmt): JSX
 with comments now formats stably
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

`deno fmt` panics with `Formatting not stable. Bailed after 5 tries` when a
`
` JSX element contains a `{/* … */}` expression-container comment, e.g.

```tsx
function ErrorPage500(props: ErrorPageProps) {
  return (
    
      {props.url}
      {/* {props.url} */}
    
); } ``` `
` element bodies in `dprint-plugin-typescript` are emitted verbatim as
raw text instead of going through the normal JSX child generation path. That
bypass skips the bookkeeping that marks comments inside the body as handled,
so when `gen_node` is later called for `
` the comment is picked up again as a leading comment of the closing tag and emitted as a JS block comment outside the expression container. Each formatting pass adds one more copy of the comment, so the formatter never stabilises. The fix is in `dprint-plugin-typescript` (dprint/dprint-plugin-typescript#796) and is consumed here via a `[patch.crates-io]` git entry until the upstream change ships in a new crates.io release. A spec regression test in `tests/specs/fmt/jsx_pre_with_comment` uses the exact input from the issue and asserts the formatter produces the same text back. Closes #20403 Closes denoland/orchid#300 Co-Authored-By: Divy Srivastava --- Cargo.lock | 3 +-- Cargo.toml | 6 ++++++ tests/specs/fmt/jsx_pre_with_comment/__test__.jsonc | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/specs/fmt/jsx_pre_with_comment/__test__.jsonc diff --git a/Cargo.lock b/Cargo.lock index fec331a26fcc32..4c98c5a926a67f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4021,8 +4021,7 @@ dependencies = [ [[package]] name = "dprint-plugin-typescript" version = "0.96.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90733c56ab425fc299c25ad81a5924bfc3c0050f25d865da742a6987b1255927" +source = "git+https://github.com/divybot/dprint-plugin-typescript?rev=7b7b2a2df15b02e7bba2b9bc32f011961b002cc2#7b7b2a2df15b02e7bba2b9bc32f011961b002cc2" dependencies = [ "anyhow", "capacity_builder", diff --git a/Cargo.toml b/Cargo.toml index eb79a9acd8f1ad..6adaa038e68706 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -610,3 +610,9 @@ opt-level = 3 opt-level = 3 [profile.release.package.twox-hash] opt-level = 3 + +[patch.crates-io] +# Temporary until dprint/dprint-plugin-typescript#796 is released, which fixes +# unstable JSX formatting for
 elements that contain comments. Tracks
+# denoland/deno#20403.
+dprint-plugin-typescript = { git = "https://github.com/divybot/dprint-plugin-typescript", rev = "7b7b2a2df15b02e7bba2b9bc32f011961b002cc2" }
diff --git a/tests/specs/fmt/jsx_pre_with_comment/__test__.jsonc b/tests/specs/fmt/jsx_pre_with_comment/__test__.jsonc
new file mode 100644
index 00000000000000..1c616d7c54ce69
--- /dev/null
+++ b/tests/specs/fmt/jsx_pre_with_comment/__test__.jsonc
@@ -0,0 +1,10 @@
+{
+  "tempDir": true,
+  "tests": {
+    "stdin": {
+      "args": "fmt --ext=tsx -",
+      "input": "import { ErrorPageProps } from \"$fresh/server.ts\";\n\nexport default function ErrorPage500(props: ErrorPageProps) {\n  return (\n    
\n      {props.url}\n      {/* {props.url} */}\n    
\n );\n}\n", + "output": "import { ErrorPageProps } from \"$fresh/server.ts\";\n\nexport default function ErrorPage500(props: ErrorPageProps) {\n return (\n
\n      {props.url}\n      {/* {props.url} */}\n    
\n );\n}\n" + } + } +} From d7958293d94f6ab6398ecd3ec0f514e0e3ebc0ef Mon Sep 17 00:00:00 2001 From: divybot Date: Sat, 30 May 2026 04:07:31 +0000 Subject: [PATCH 2/2] test(fmt): move jsx_pre_with_comment expected output into expected.out `tests/specs/mod.rs` panics if an inline `output` string exceeds 160 characters, so the spec test for the JSX `
` comment regression
failed on every platform with "The 'output' property in your
__test__.jsonc file is too long." Extract the expected text into
`expected.out` and reference it from `__test__.jsonc`.

Co-Authored-By: Divy Srivastava 
---
 tests/specs/fmt/jsx_pre_with_comment/__test__.jsonc |  2 +-
 tests/specs/fmt/jsx_pre_with_comment/expected.out   | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 tests/specs/fmt/jsx_pre_with_comment/expected.out

diff --git a/tests/specs/fmt/jsx_pre_with_comment/__test__.jsonc b/tests/specs/fmt/jsx_pre_with_comment/__test__.jsonc
index 1c616d7c54ce69..351a55bba0e195 100644
--- a/tests/specs/fmt/jsx_pre_with_comment/__test__.jsonc
+++ b/tests/specs/fmt/jsx_pre_with_comment/__test__.jsonc
@@ -4,7 +4,7 @@
     "stdin": {
       "args": "fmt --ext=tsx -",
       "input": "import { ErrorPageProps } from \"$fresh/server.ts\";\n\nexport default function ErrorPage500(props: ErrorPageProps) {\n  return (\n    
\n      {props.url}\n      {/* {props.url} */}\n    
\n );\n}\n", - "output": "import { ErrorPageProps } from \"$fresh/server.ts\";\n\nexport default function ErrorPage500(props: ErrorPageProps) {\n return (\n
\n      {props.url}\n      {/* {props.url} */}\n    
\n );\n}\n" + "output": "expected.out" } } } diff --git a/tests/specs/fmt/jsx_pre_with_comment/expected.out b/tests/specs/fmt/jsx_pre_with_comment/expected.out new file mode 100644 index 00000000000000..2c6e93624bd721 --- /dev/null +++ b/tests/specs/fmt/jsx_pre_with_comment/expected.out @@ -0,0 +1,10 @@ +import { ErrorPageProps } from "$fresh/server.ts"; + +export default function ErrorPage500(props: ErrorPageProps) { + return ( +
+      {props.url}
+      {/* {props.url} */}
+    
+ ); +}