Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Fix context cache when using literal config object instead of file #11

Merged
merged 1 commit into from
Mar 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/lib/setupContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ function setupContext(configOrPath) {

let sourcePath = result.opts.from
let [tailwindConfig, userConfigPath, tailwindConfigHash] = getTailwindConfig(configOrPath)
let isConfigFile = userConfigPath !== null

let contextDependencies = new Set()

Expand All @@ -646,27 +647,28 @@ function setupContext(configOrPath) {
}
}

if (userConfigPath !== null) {
if (isConfigFile) {
contextDependencies.add(userConfigPath)
}

let contextDependenciesChanged =
trackModified([...contextDependencies]) || userConfigPath === null
let contextDependenciesChanged = trackModified([...contextDependencies])

process.env.DEBUG && console.log('Source path:', sourcePath)

// If this file already has a context in the cache and we don't need to
// reset the context, return the cached context.
if (contextMap.has(sourcePath) && !contextDependenciesChanged) {
return contextMap.get(sourcePath)
}
if (!contextDependenciesChanged) {
// If this file already has a context in the cache and we don't need to
// reset the context, return the cached context.
if (isConfigFile && contextMap.has(sourcePath)) {
return contextMap.get(sourcePath)
}

// If the config file used already exists in the cache, return that.
if (!contextDependenciesChanged && configContextMap.has(tailwindConfigHash)) {
let context = configContextMap.get(tailwindConfigHash)
contextSourcesMap.get(context).add(sourcePath)
contextMap.set(sourcePath, context)
return context
// If the config used already exists in the cache, return that.
if (configContextMap.has(tailwindConfigHash)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this need && !isConfigFile?

Copy link
Member

Choose a reason for hiding this comment

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

I... don't know 😅 I don't think so, I think this is right. If we don't have a context in the map for the current source path (real world example is MyComponent.vue with a style block), we want to try and reuse the context based on the config hash and then set up that source path in the map. True even if there's a config file if I'm not missing something.

let context = configContextMap.get(tailwindConfigHash)
contextSourcesMap.get(context).add(sourcePath)
contextMap.set(sourcePath, context)
return context
}
}

// If this source is in the context map, get the old context.
Expand Down Expand Up @@ -723,7 +725,7 @@ function setupContext(configOrPath) {

// ---

if (userConfigPath !== null) {
if (isConfigFile) {
for (let dependency of getModuleDependencies(userConfigPath)) {
if (dependency.file === userConfigPath) {
continue
Expand Down