refactor: split cn into cn and cnMerge functions #286
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR splits the
cnfunction into two separate functions (cnandcnMerge) to eliminate the Proxy complexity that was causing errors. The previous implementation used a Proxy to support dual usage patterns (direct usage and config-based usage), which introduced complexity and type issues.Changes:
cn: Simplified function that returns a string directly with default twMerge config. No function call needed - justcn("px-2", "px-4")returns"px-4".cnMerge: New function that supports custom twMerge config via a second function call. Usage:cnMerge("px-2", "px-4")({twMerge: false})returns"px-2 px-4".Implementation details:
executeMergehelper functioncore.jsto usecnMergefor config-based calls (passed as parameter togetTailwindVariants)cx,cn, andcnMergeAdditional context
This is a breaking change for users who were calling
cn(...)()with an empty call or relying on the Proxy's string coercion. However, the common use case ofcn("...")now works more intuitively by returning a string directly. Users who need custom config should migrate tocnMerge.The split provides:
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).