Skip to content

fix(react): read the important marker only at the end of a value - #10970

Merged
Adebesin-Cell merged 3 commits into
chakra-ui:mainfrom
MaxFreedomPollard:important-marker-at-end
Sep 7, 2026
Merged

Adebesin-Cell merged 3 commits into
chakra-ui:mainfrom
MaxFreedomPollard:important-marker-at-end

Conversation

@MaxFreedomPollard

@MaxFreedomPollard MaxFreedomPollard commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

📝 Description

css() treats any exclamation mark in a string value as the !important marker. importantRegex in packages/react/src/styled-system/css.ts:15 is /\s*!(important)?/i, with no end anchor, so isImportant fires for content: '"!"' as readily as for color: "red!". withoutImportant then deletes the first ! it finds, wherever it is, and the second walkObject pass appends !important to every string in the transformed result. Measured on defaultSystem.css at main: content: '"Hello!"' emits content: "Hello" !important; _before: { content: '"!"' } emits &::before { content: "" !important }, so a badge meant to show an exclamation mark renders empty; backgroundImage: "url(/a!b.png)" emits url(/ab.png) !important, a broken URL; fontFamily: "'Wow! Sans', sans-serif" becomes 'Wow Sans', sans-serif !important.

The fix anchors the marker to the end of the value: /\s*!(important)?\s*$/i. Trailing whitespace is tolerated so "red!important " still counts, as it did before. @pandacss/shared carries the same unanchored regex (shared.mjs:38 in 1.11.1), so the same anchor applies there.

⛳️ Current behavior (updates)

Any ! inside a style value is stripped and the value is emitted with !important.

🚀 New behavior

Only a trailing ! or !important is read as the marker. Values containing an exclamation mark elsewhere pass through unchanged; color: "red!", color: "red !important" and color: "red!important " all still resolve to color: "red !important".

💣 Is this a breaking change (Yes/No):

No.

📝 Additional Information

One regression test in packages/react/__tests__/css.test.ts covers the four mangled cases and the three marker spellings; it fails on main at the first assertion and passes with the change. pnpm vitest run packages/react: 33 files, 195 tests passing. pnpm typecheck and Prettier are clean. Patch changeset for @chakra-ui/react included.

Greptile Summary

This PR narrows Chakra’s shorthand !important detection to terminal markers, preserving exclamation marks embedded in CSS values.

  • Anchors importantRegex to the end of the value while allowing trailing whitespace.
  • Adds regression coverage for quoted content, URLs, font families, and supported marker spellings.
  • Adds a patch changeset for @chakra-ui/react.

Confidence Score: 5/5

The PR appears safe to merge, with no actionable correctness, security, or repository-rule issues identified.

The narrowed regex preserves all supported terminal marker spellings while preventing embedded exclamation marks from entering the marker-removal path, and the regression tests cover the representative affected values.

Important Files Changed

Filename Overview
packages/react/src/styled-system/css.ts Correctly anchors important-marker recognition without changing supported trailing marker forms.
packages/react/tests/css.test.ts Adds focused regression tests for embedded exclamation marks and terminal important-marker variants.
.changeset/important-marker-at-end.md Accurately documents the user-visible fix as a patch release.

Reviews (1): Last reviewed commit: "fix(react): read the important marker on..." | Re-trigger Greptile

`importantRegex` had no end anchor, so any exclamation mark inside a
style value was taken as the `!important` marker: the `!` was deleted
from the value and ` !important` appended. `content: '"!"'` rendered as
an empty string and `url(/a!b.png)` became `url(/ab.png)`. Anchor the
marker to the end of the value, tolerating trailing whitespace so
`"red!important "` keeps working.
@changeset-bot

changeset-bot Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 29809ab

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@chakra-ui/react Patch
@chakra-ui/charts Patch
@chakra-ui/cli Patch
@chakra-ui/codemod Patch
tanstack-router-ts Patch
@chakra-ui/panda-preset Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
chakra-ui-storybook Ready Ready Preview Sep 7, 2026 2:16pm UTC
chakra-v3-docs Ready Ready Preview Sep 7, 2026 2:16pm UTC

Request Review

@Adebesin-Cell Adebesin-Cell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you! We fixed the important issue in v2 for panda, I'll check if it still exists in v1.

@Adebesin-Cell
Adebesin-Cell merged commit d88c3e9 into chakra-ui:main Sep 7, 2026
0 of 2 checks passed
@github-actions github-actions Bot mentioned this pull request Sep 7, 2026

This branch was successfully deployed

2 active deployments
Preview – chakra-v3-docs — 29809ab0 Deployed Sep 7, 2026 by vercel[bot]
Preview – chakra-ui-storybook — 29809ab0 Deployed Sep 7, 2026 by vercel[bot]
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