Skip to content

Conversation

@thecrypticace
Copy link
Contributor

Fixes #19362

We were overwriting the source map with the "decoded" map returned by the compiler but didn't wrap it in the helper intended to help inline vs file maps. This resulted in two issues:

  1. undefined being appended to the CSS file when using --map
  2. undefined being passed to writeFile(…) when using --map <file>

This PR fixes both.

@thecrypticace thecrypticace requested a review from a team as a code owner November 25, 2025 15:02
@coderabbitai
Copy link

coderabbitai bot commented Nov 25, 2025

Walkthrough

Replaces direct casting of compiler.buildSourceMap() with toSourceMap(compiler.buildSourceMap()) in the CLI build/rebuild paths to ensure proper SourceMap typing. Adds watch-mode tests covering inline and external source maps, validating initial builds, rebuilds after CSS edits, and parity between CLI and Standalone CLI. Updates CHANGELOG.md with a Fixed entry noting correct source map writing in CLI --watch mode.

Pre-merge checks

✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: correcting source map generation during watch mode on the CLI.
Description check ✅ Passed The description clearly explains the root cause and the two issues being fixed, directly relating to the changeset.
Linked Issues check ✅ Passed The PR comprehensively addresses both objectives from issue #19362: fixing 'undefined' appended to CSS with --map and TypeError with --map in watch mode.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing source map generation in watch mode: CHANGELOG entry, tests validating the fix, and the core fix wrapping compiler output with toSourceMap().

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 068a1ec and 12c476d.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • integrations/cli/index.test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md
⏰ 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). (5)
  • GitHub Check: Linux / postcss
  • GitHub Check: Linux / vite
  • GitHub Check: Linux / cli
  • GitHub Check: Linux / upgrade
  • GitHub Check: Linux
🔇 Additional comments (3)
integrations/cli/index.test.ts (3)

6-6: LGTM!

The retryAssertion import is correctly added and appropriately used in the new watch mode tests to handle asynchronous file system operations.


823-844: Good test coverage for the source map bug fix.

The new watch mode tests comprehensively validate both inline and separate source map scenarios, covering the exact issues reported in #19362:

  • Initial build source map generation
  • Source map updates after file changes
  • Both --map (inline) and --map <file> (external) modes

Once the expectation values are corrected per the duplicate comments, these tests will properly prevent regression.


1000-1004: Unable to verify without test execution results.

The script confirms lines 1003 and 1027 match the snippet shown. However, determining whether these assertions are incorrect requires either:

  1. Test execution output showing what map.at() actually returns, or
  2. Understanding the code logic that generates these source map values

The current assertions show an inconsistent pattern: most map.at(4, 0) calls expect '}...', while a few expect expanded strings like '}\n.underli...' or '}\n.w-auto...'. Without CI test results or code analysis, I cannot confirm if lines 1003 and 1027 need adjustment.


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

Copy link

@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: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 28670a9 and 068a1ec.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • integrations/cli/index.test.ts (1 hunks)
  • packages/@tailwindcss-cli/src/commands/build/index.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/@tailwindcss-cli/src/commands/build/index.ts (1)
packages/@tailwindcss-node/src/source-maps.ts (1)
  • toSourceMap (44-59)
🪛 GitHub Check: Linux / cli
integrations/cli/index.test.ts

[failure] 1145-1145: cli/index.test.ts > Standalone CLI > watch mode + separate source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:1145:28
❯ utils.ts:453:14


[failure] 919-919: cli/index.test.ts > Standalone CLI > watch mode + inline source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:919:28
❯ utils.ts:453:14


[failure] 919-919: cli/index.test.ts > Standalone CLI > watch mode + inline source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:919:28
❯ utils.ts:453:14


[failure] 919-919: cli/index.test.ts > Standalone CLI > watch mode + inline source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:919:28
❯ utils.ts:453:14


[failure] 1145-1145: cli/index.test.ts > CLI > watch mode + separate source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:1145:28
❯ utils.ts:453:14


[failure] 1145-1145: cli/index.test.ts > CLI > watch mode + separate source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:1145:28
❯ utils.ts:453:14


[failure] 1145-1145: cli/index.test.ts > CLI > watch mode + separate source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:1145:28
❯ utils.ts:453:14


[failure] 919-919: cli/index.test.ts > CLI > watch mode + inline source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:919:28
❯ utils.ts:453:14


[failure] 919-919: cli/index.test.ts > CLI > watch mode + inline source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:919:28
❯ utils.ts:453:14


[failure] 919-919: cli/index.test.ts > CLI > watch mode + inline source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:919:28
❯ utils.ts:453:14

⏰ 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). (2)
  • GitHub Check: Linux / upgrade
  • GitHub Check: Linux
🔇 Additional comments (2)
packages/@tailwindcss-cli/src/commands/build/index.ts (2)

324-325: Use toSourceMap in watch rebuilds for consistent map handling

Wrapping compiler.buildSourceMap() with toSourceMap(…) in both full and incremental watch rebuilds aligns the watch paths with the expectations of write(…) (raw + inline) and with the initial-build behavior. This should prevent malformed or undefined map data from being appended inline or written to files during --watch rebuilds.

Also applies to: 349-350


392-395: Consistent toSourceMap usage for initial build source maps

Using toSourceMap(compiler.buildSourceMap()) inside handleError for the initial build ensures the source map always conforms to the SourceMap shape expected downstream, and keeps error handling behavior unchanged.

@thecrypticace thecrypticace merged commit 0e8f075 into main Nov 25, 2025
7 checks passed
@thecrypticace thecrypticace deleted the fix/issue-19362 branch November 25, 2025 17:23
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.

v4 CLI: --watch --map appends "undefined" to output; --map <file> triggers TypeError [ERR_INVALID_ARG_TYPE]

2 participants