Skip to content

Commit 9446822

Browse files
committed
Include all css in context
1 parent e8e64f0 commit 9446822

File tree

3 files changed

+47
-26
lines changed

3 files changed

+47
-26
lines changed

src/lib/setupTrackingContext.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,13 @@ export default function setupTrackingContext(configOrPath) {
119119

120120
let contextDependencies = new Set(configDependencies)
121121

122-
// If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
123-
// to be dependencies of the context. Can reuse the context even if they change.
124-
// We may want to think about `@layer` being part of this trigger too, but it's tough
125-
// because it's impossible for a layer in one file to end up in the actual @tailwind rule
126-
// in another file since independent sources are effectively isolated.
127-
if (tailwindDirectives.size > 0) {
128-
// Add current css file as a context dependencies.
129-
contextDependencies.add(result.opts.from)
122+
// Add current css file as a context dependencies.
123+
contextDependencies.add(result.opts.from)
130124

131-
// Add all css @import dependencies as context dependencies.
132-
for (let message of result.messages) {
133-
if (message.type === 'dependency') {
134-
contextDependencies.add(message.file)
135-
}
125+
// Add all css @import dependencies as context dependencies.
126+
for (let message of result.messages) {
127+
if (message.type === 'dependency') {
128+
contextDependencies.add(message.file)
136129
}
137130
}
138131

src/lib/setupWatchingContext.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,13 @@ export default function setupWatchingContext(configOrPath) {
236236

237237
let contextDependencies = new Set(configDependencies)
238238

239-
// If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
240-
// to be dependencies of the context. Can reuse the context even if they change.
241-
// We may want to think about `@layer` being part of this trigger too, but it's tough
242-
// because it's impossible for a layer in one file to end up in the actual @tailwind rule
243-
// in another file since independent sources are effectively isolated.
244-
if (tailwindDirectives.size > 0) {
245-
// Add current css file as a context dependencies.
246-
contextDependencies.add(result.opts.from)
239+
// Add current css file as a context dependencies.
240+
contextDependencies.add(result.opts.from)
247241

248-
// Add all css @import dependencies as context dependencies.
249-
for (let message of result.messages) {
250-
if (message.type === 'dependency') {
251-
contextDependencies.add(message.file)
252-
}
242+
// Add all css @import dependencies as context dependencies.
243+
for (let message of result.messages) {
244+
if (message.type === 'dependency') {
245+
contextDependencies.add(message.file)
253246
}
254247
}
255248

tests/apply.test.js

+35
Original file line numberDiff line numberDiff line change
@@ -774,3 +774,38 @@ it('should not apply unrelated siblings when applying something from within atru
774774
`)
775775
})
776776
})
777+
778+
it('should be possible to apply user css without directives', () => {
779+
let config = {
780+
content: [{ raw: html`<div class="foo"></div>` }],
781+
plugins: [],
782+
}
783+
784+
let input = css`
785+
.bop {
786+
color: red;
787+
}
788+
.bar {
789+
background-color: blue;
790+
}
791+
.foo {
792+
@apply absolute bar bop;
793+
}
794+
`
795+
796+
return run(input, config).then((result) => {
797+
return expect(result.css).toMatchFormattedCss(css`
798+
.bop {
799+
color: red;
800+
}
801+
.bar {
802+
background-color: blue;
803+
}
804+
.foo {
805+
position: absolute;
806+
color: red;
807+
background-color: blue;
808+
}
809+
`)
810+
})
811+
})

0 commit comments

Comments
 (0)