Skip to content

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

Merged
RobinMalfait merged 3 commits into
tailwindlabs:mainfrom
kwy404:fix-container-padding-custom-screens
Nov 20, 2026
Merged

RobinMalfait merged 3 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

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent 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.

Merge Risk: Minimal · previous review 89b55

The change addresses the reported container-padding crash, and no actionable issue remains from this review. It is ready for normal merge checks.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: the build no longer crashes when a container padding key refers to a screen that is not a breakpoint. The changeset adds a filter on the resolved value in `buildCus…
Description check Passed The description explains the crash. buildCustomContainerUtilityRules calls compareBreakpoints on a null value, and the .filter(Boolean) runs on tuples instead of resolved values. It gives a co…
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.
Full details: Title check

Explanation

The title states the main change: the build no longer crashes when a container padding key refers to a screen that is not a breakpoint. The changeset adds a filter on the resolved value in buildCustomContainerUtilityRules and extends two tests that cover this case, so the title matches the primary fix.

Full details: Description check

Explanation

The description explains the crash. buildCustomContainerUtilityRules calls compareBreakpoints on a null value, and the .filter(Boolean) runs on tuples instead of resolved values. It gives a config example, describes the fix (skip keys that are neither a breakpoint nor a custom container screen), and lists the tests and validation run. It matches the changes in container.ts, the changelog, and the test files.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8ce2a62b-f825-40fb-9d30-f88acedad2e0
Commits

Reviewing files that changed from the base of the PR and between 462524f and 89b556f.

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; 9 remain after this review.

@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 Resolved
@greptile-apps

greptile-apps Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Reviews (6) · Last reviewed commit: "Move changelog entry to a fragment" · Reviewed by Greptile

Comment thread CHANGELOG.md Resolved
@kwy404
kwy404 force-pushed the fix-container-padding-custom-screens branch from 9561619 to da6b853 Compare October 12, 2026 19:08
@greptile-apps

greptile-apps Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@RobinMalfait
RobinMalfait self-requested a review November 20, 2026 15:33
@RobinMalfait RobinMalfait self-assigned this Nov 20, 2026
kwy404 and others added 3 commits November 20, 2026 16:36
The PR added its entry to `CHANGELOG.md`. Entries now go in a fragment
in `.changelog/`, which the "Compile changelog" workflow moves into
`CHANGELOG.md` after the merge, with the PR link.
@RobinMalfait
RobinMalfait force-pushed the fix-container-padding-custom-screens branch from 89b556f to d8e9bac Compare November 20, 2026 15:39
@RobinMalfait

Copy link
Copy Markdown
Contributor

I rebased this PR on the latest main and force pushed it. The rebase had merge conflicts in CHANGELOG.md, and I resolved them.

Sent by an AI assistant on behalf of @RobinMalfait.

@RobinMalfait
RobinMalfait enabled auto-merge (squash) November 20, 2026 16:04

@RobinMalfait RobinMalfait 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.

Thanks for the PR! Nice catch on the .filter(Boolean) that never filtered anything.

Sent by an AI assistant on behalf of @RobinMalfait.

@RobinMalfait
RobinMalfait merged commit 0607226 into tailwindlabs:main Nov 20, 2026
13 checks passed
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