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

Modifying props during development doesn't update page #24

Closed
djmtype opened this issue Oct 31, 2022 · 3 comments
Closed

Modifying props during development doesn't update page #24

djmtype opened this issue Oct 31, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@djmtype
Copy link

djmtype commented Oct 31, 2022

Given the setup below, if I was to add/remove/change any css variables within props.css, those changes will not update during development. Unsure if this is a stipulation of this plugin.
Tested with Astro 1.6 and PostCSS 8.4.18

postcssJitProps({
  files: ['./src/styles/common/props.css'],
})
@argyleink argyleink added the enhancement New feature or request label Oct 31, 2022
@argyleink
Copy link
Collaborator

yes, makes sense, i'm reading from a file and not watching it also..

feature request: watch files for changes and update var pool

@romainmenke
Copy link
Contributor

Can be done with two changes :

  • emit dependency messages (see postcss-import)
  • use prepare in the PostCSS plugin

The dependency messages communicate to a build tool (like postcss-cli) that that tool should watch certain files.

prepare should give you a blank slate each time the plugin is run.

This avoids issues where someone removes properties from the source but that not being reflected in the plugin state.

module.exports = (UserProps) => {
  const STATE = {}

  return {
    postcssPlugin: 'postcss-jit-props',
    async Once (node, {Rule, AtRule}) {
    ...

->

module.exports = (UserProps) => {
  return {
    postcssPlugin: 'postcss-jit-props',
    prepare() {
      const STATE = {}
      
      return {
        async Once (node, {Rule, AtRule}) {
        ...

I've noticed that switching to prepare can have unexpected side effects.

Some build tools run a single plugin instance in parallel against multiple source files.
This creates subtle dependencies on the plugin having a specific state when processing specific files in a specific order.

Using prepare ensures that each file will have its own state when processed.
Normally this would fix bugs, but in rare cases it can surface issues for users.

@argyleink
Copy link
Collaborator

fixed in v1.0.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants