Skip to content

Don't crash when container padding uses a screen that isn't a breakpoint - #20523

Open
kwy404 wants to merge 2 commits into
tailwindlabs:mainfrom
kwy404:fix-container-padding-custom-screens
Open

kwy404 wants to merge 2 commits into
tailwindlabs:mainfrom
kwy404:fix-container-padding-custom-screens

Conversation

@kwy404

@kwy404 kwy404 commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Summary

buildCustomContainerUtilityRules (used for the legacy theme.container config and by @tailwindcss/upgrade) resolves every padding key with theme.resolveValue(key, ['--breakpoint']) and sorts the result with compareBreakpoints. A key that isn't a breakpoint resolves to null, and compareBreakpoints then calls null.indexOf('('), so the build throws TypeError: Cannot read properties of null (reading 'indexOf'). The .filter(Boolean) after the map looks like it was meant to drop those keys, but it runs on the [key, breakpoint, value] tuples, which are always truthy.

This happens with a valid v3 config where a padding key is only defined as a container screen:

container: {
  padding: { xs: '1rem', md: '2rem' },
  screens: { xs: '30rem', md: '48rem' },
}

Without custom screens, a padding key that isn't a breakpoint crashes the same way, or, when it is the only one, makes the whole container utility disappear because theme(--breakpoint-xs) can't be resolved.

The fix filters on the resolved value instead: keys that are neither a breakpoint nor a custom container screen are skipped, like in v3. With custom container screens, each padding value is added to that screen's own rule, so the sort is only done when there are no custom screens.

Test plan

  • Extended two tests in packages/tailwindcss/src/compat/container-config.test.ts. Both fail before the change with the TypeError above and pass after it:
    • padding applies to custom container screens now has an xs container screen with xs padding, and the snapshot gains the @media (min-width: 30rem) rule with padding-inline: 1rem.
    • allows padding to be defined at custom breakpoints now has an xs padding key that isn't a breakpoint. The snapshot is unchanged because the key is ignored.
  • vitest run src/compat/container-config.test.ts (in packages/tailwindcss)
  • vitest run (in packages/tailwindcss): 42 files, 5015 tests passed
  • prettier --check on the changed files

@kwy404
kwy404 requested a review from a team as a code owner September 27, 2026 02:44
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 056f95a8-3b17-4fd0-b722-6baa5a262e90

📥 Commits

Reviewing files that changed from the base of the PR and between 05eeca5 and 9561619.

📒 Files selected for processing (1)
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


Walkthrough

Legacy container padding keys are retained when they match a configured breakpoint or custom container screen. Unmatched keys are skipped. Custom-screen padding is added to its screen rule, and padding is sorted only when there are no custom screen overwrites. Tests cover unmatched xs padding and an xs screen at 30rem.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 95616

The reviewed container-padding behavior matches the intended handling of unknown keys and custom screens. No actionable issue remains before merge.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: preventing crashes when container padding references a screen that is not a breakpoint.
Description check ✅ Passed The description directly explains the crash, affected code, fix, test changes, and validation results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e3e0f1f9-78b6-4c01-a75e-119fdc245fde

📥 Commits

Reviewing files that changed from the base of the PR and between fa81d69 and 05eeca5.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • packages/tailwindcss/src/compat/container-config.test.ts
  • packages/tailwindcss/src/compat/container.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread CHANGELOG.md Outdated
@greptile-apps

greptile-apps Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Fixes crash in container padding configuration handling.

The PR appears safe to merge; the previously reported changelog link is corrected and no new issue was identified.

Reviews (2) · Last reviewed commit: "Update changelog entry with PR number"

Comment thread CHANGELOG.md Outdated
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.

1 participant