Skip to content

Invalid mapping (generated column -1) when CSS contains <style and HTML escaping applies #2168

Closed

Description

@Rufflet

Since 8.5.29, SafeStringifier.escapeHTML escapes <style / <!-- in the output. When escaping kicks in, the source map generator adds a mapping with generated.column: -1, and source-map-js prints Invalid mapping.

Reproduction

import postcss from 'postcss'

const css = '/* see <style> */\na { color: red }\n'
const result = await postcss([{ postcssPlugin: 'noop', Once() {} }])
  .process(css, { from: 'in.css', map: { inline: false } })
console.log(result.css)

Output (postcss 8.5.29, Node 24):

Invalid mapping: {"generated":{"column":-1,"line":3},"source":"in.css","original":{"column":0,"line":3},"name":null}
/* see \3c style> */
a { color: red }

Without <style in the CSS there is no warning.

Cause

In lib/stringify.js, if the escaped CSS differs from the original, the whole string is passed to the builder at once: builder(escaped, node) with the root node and no type. MapGenerator.generateString then treats it as both start and end of the root. For the end mapping it uses column - 2, and when the escaped string ends with \n, column is 1, so the generated column becomes -1.

Real-world impact

Vite 8 depends on postcss@^8.5.29, so any Vue SFC <style> block whose comment mentions <style> (for example /* keep this in <style> */) prints Invalid mapping in nuxt dev / vite dev.

Activity

  1. ai commented on Oct 9, 2026

    @ai
    Member

    Please send PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions