diff --git a/packages/@tailwindcss-cli/src/commands/build/index.ts b/packages/@tailwindcss-cli/src/commands/build/index.ts index ca3859b6e..7d007f308 100644 --- a/packages/@tailwindcss-cli/src/commands/build/index.ts +++ b/packages/@tailwindcss-cli/src/commands/build/index.ts @@ -196,7 +196,9 @@ export async function handle(args: Result>) { // Scan changed files only for incremental rebuilds. else if (rebuildStrategy === 'incremental') { - compiledCss = result.rebuild(scanFiles(changedFiles, IO.Sequential | Parsing.Sequential)) + let newCandidates = scanFiles(changedFiles, IO.Sequential | Parsing.Sequential) + + compiledCss = result.rebuild(newCandidates) } await write(compiledCss, args) diff --git a/packages/tailwindcss/src/design-system.ts b/packages/tailwindcss/src/design-system.ts index fa6390f0a..22277eda3 100644 --- a/packages/tailwindcss/src/design-system.ts +++ b/packages/tailwindcss/src/design-system.ts @@ -32,8 +32,8 @@ export type DesignSystem = { export function buildDesignSystem(theme: Theme): DesignSystem { let utilities = createUtilities(theme) let variants = createVariants(theme) - let invalidRawCandidates = new Set() + let invalidRawCandidates = new Set() let parsedVariants = new DefaultMap((variant) => parseVariant(variant, designSystem)) let parsedCandidates = new DefaultMap((candidate) => parseCandidate(candidate, designSystem)) let compiledAstNodes = new DefaultMap((candidate) => compileAstNodes(candidate, designSystem)) diff --git a/packages/tailwindcss/src/index.ts b/packages/tailwindcss/src/index.ts index d5205bd52..cb5559a1b 100644 --- a/packages/tailwindcss/src/index.ts +++ b/packages/tailwindcss/src/index.ts @@ -187,17 +187,20 @@ export function compile( return { rebuild(newRawCandidates: string[]) { + let didChange = false + // Add all new candidates unless we know that they are invalid. - let previousSize = allValidCandidates.size + let prevSize = allValidCandidates.size for (let candidate of newRawCandidates) { if (!designSystem.isInvalidCandidate(candidate)) { allValidCandidates.add(candidate) + didChange ||= allValidCandidates.size !== prevSize } } // If no new candidates were added, we can return the original CSS. This // currently assumes that we only add new candidates and never remove any. - if (previousSize === allValidCandidates.size) { + if (!didChange) { return compiledCss }