Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore theme.json updates to Tailwind configuration during watch process #79

Closed
gregsullivan opened this issue Nov 13, 2023 Discussed in #78 · 1 comment
Closed
Assignees
Labels
Type: Regression Things that used to work, but don’t anymore

Comments

@gregsullivan
Copy link
Owner

Previous functionality

Updating the theme.json file would trigger Tailwind to rebuild the CSS file with new colour and width properties from the theme.json file.

Current status

Two things seem to have changed:

  1. Opening the theme.json file with require caches its contents, and those contents aren't updated when the file changes.
  2. Tailwind no longer executes the plugin except on startup and when rebuilding the configuration after changes to tailwind.config.js.

Workaround

Right now, the easiest way around this is to terminate the watch process after changing the theme.json file and then to restart it.

Future fixes

There are two options for the caching issue:

  1. Clear the require cache
  2. Open and parse the JSON file without using require

I'm not sure which would be more performant, or if it would make enough of a different to matter.

I want to wait until Tailwind's Oxide compiler is released before putting too much energy into the second issue. One approach that would definitely work would be to watch the theme.json file and then to trigger something equivalent to touch tailwind.config.js. I'd prefer not to add more dependencies, though, and it feels like there should be a better way.

That said, my sense is that Tailwind has consciously been updated to run plugins less often, and that plugins that could produce different values on future runs may have limited options.

Discussed in #78

Originally posted by victorcl November 13, 2023
Hi and thanks for this great wordpress theme starter.

I am having an issue which I haven't been able to sort out. When I make changes to the theme.json, watch gets triggered with "Rebuilding..." but these changes are not available to tailwind.
But if I run "npm run dev" then the changes from theme.json are available to tailwing. But then if I make a change to any other file that triggers "watch" then I loose the theme.json changes again, they reset to the original values.
Any idea¿

Thanks.

@gregsullivan gregsullivan changed the title Restore theme.json updates Tailwind configuration during watch process Restore theme.json updates to Tailwind configuration during watch process Nov 14, 2023
@gregsullivan gregsullivan self-assigned this Nov 14, 2023
@gregsullivan gregsullivan added the Type: Regression Things that used to work, but don’t anymore label Nov 14, 2023
gregsullivan added a commit that referenced this issue Nov 16, 2023
There were two problems here:

* Opening the `theme.json` file with `require` now caches its contents, and those contents aren’t updated when the file changes.
* Tailwind no longer executes the plugin except on startup and when rebuilding the configuration after changes to `tailwind.config.js`.

To overcome the caching issue, `require` is no longer used to load the `theme.json` file; that logic has been moved to the `@_tw/themejson` package (in a backwards-compatible manner).

To force Tailwind to rebuild the configuration, `chokidar-cli` is used to watch the `theme.json` file and to trigger `nodetouch` on the `tailwind.config.js` file when `theme.json` changes.

Depending on how things change post-Oxide, this may need to be revisited.
@gregsullivan
Copy link
Owner Author

I change my mind and fixed this for now:

1fcc039

This will need to be revisited after Oxide launches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Regression Things that used to work, but don’t anymore
Projects
None yet
Development

No branches or pull requests

1 participant