Skip to content

Callback in theme properties is also the theme function #14659

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

Merged
merged 2 commits into from
Oct 14, 2024

Conversation

philipp-spiess
Copy link
Member

Something we noticed while testing the codemods on one of our codebases is that the callback passed to the theme function properties doesn't only expose some properties like colors, but it's also a function itself.

/** @type {import('tailwindcss').Config} */
export default {
  theme: {
    extend: {
      colors: (theme) => {
        // The `theme` is a theme function _and_ the object...
        console.log(theme('spacing.2'), theme.colors.red['500'])
        return {}
      },
    },
  },
  plugins: [],
}

E.g.: https://play.tailwindcss.com/eV7Jgv17X1?file=config


h/t to @RobinMalfait for the issue description

@philipp-spiess philipp-spiess force-pushed the fix/theme-fn-parameter-is-also-a-fn branch from 04e533b to 5410f18 Compare October 14, 2024 09:40
Copy link
Member

@RobinMalfait RobinMalfait left a comment

Choose a reason for hiding this comment

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

Nice!

@RobinMalfait
Copy link
Member

Looks like we do have some type issues but otherwise this looks good

@philipp-spiess philipp-spiess enabled auto-merge (squash) October 14, 2024 10:25
@philipp-spiess philipp-spiess merged commit 99f2127 into next Oct 14, 2024
1 check passed
@philipp-spiess philipp-spiess deleted the fix/theme-fn-parameter-is-also-a-fn branch October 14, 2024 10:29
colors,
}
})
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm like 95% sure this is not documented anywhere. Pretty sure the types for v3 consider this usage invalid too. We'll still need to support it for B/C reasons but I think we should introduce a wrapper function that warns the first time its used.

cc @philipp-spiess @RobinMalfait thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

See #14661

philipp-spiess added a commit that referenced this pull request Oct 14, 2024
Quick follow-up to #14659 base don @thecrypticace's idea:

- This behavior is no longer added to the types of the Plugin API to be
consistent with v3
- When the plugin argument is used as a function, we now warn the first
time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants