Giter Site home page Giter Site logo

Comments (10)

sastan avatar sastan commented on August 22, 2024 2

With this PR we have a way to detect such grouping and throw an error. We could instead stop creating the optimization and fallback to the slow interleave mode we used to have in beamwind & oceanwind. That would mean fast for most cases and slow for this one. Maybe we could warn when we are using slow parsing.

from twind.

lukejacksonn avatar lukejacksonn commented on August 22, 2024 2

Yeh, like @gojutin says, I think it is one of the big advantages we are afforded when taking a runtime approach. If we can get away with is without too much code disruption then we should do it.

Regards warning, I'm not too sure if it is even necessary to be honest.. when we say "slow" we still mean tens of thousands of operations per second 😅 and like you say @sastan this is not a usual case.

from twind.

sastan avatar sastan commented on August 22, 2024 1

Currently we assume that interpolation value will not affect groupings. In that case it starts a new grouping which leads to the error.

I'll look into it.

from twind.

sastan avatar sastan commented on August 22, 2024

Here are my findings:

For performance reasons we assume that template literal strings do not change. Do that we can pre-calculate all groupings and static rules which are later combined with the dynamic rules from interpolations.

For this to work we assume that interpolations are only used as last part of a grouping. Meaning interpolations can not be used as a part of a new grouping.

Valid:

tw`text(${'center'} underline)`
tw`text-${'center'}`
tw`hover:(text(${'center'}))`
tw`bg-${'red-600'}`
tw`bg-${'red-600'} hover:bg-${'red-700'} focus:bg-${'red-700'}`

Invalid:

tw`bg-${'red'}-600`
tw`bg(${'red'}(600 700(hover:&))`

I currently see two ways the handle such a interpolation:

  1. Fail with hint – implemented in #56
  2. Fallback to slow parsing

@lukejacksonn What do you think?

from twind.

lukejacksonn avatar lukejacksonn commented on August 22, 2024

This is a tough one.. part of me thinks that this should be possible:

tw`bg-${'red'}-600`

When you say fallback to slow parsing, would it be just for these cases or for all cases? Could we detect that you are interpolating part way through a directive/grouping and then not cache that bit? This seems like a best of both worlds outcome for DX but might add some unwanted complexity?

from twind.

just214 avatar just214 commented on August 22, 2024

This is a tough one.. part of me thinks that this should be possible:

tw`bg-${'red'}-600`

I also like being able to get granular with dynamic class generation, even if it means a small performance hit. Also, this feature is another big improvement since certain dynamic classes in Tailwind would often lead to unintended purging during the build step.

from twind.

sastan avatar sastan commented on August 22, 2024

There seems to be consent that we should support this.

Should we warn when deopt?

from twind.

just214 avatar just214 commented on August 22, 2024

I think a warning in development env would be nice. Maybe even eventually a linting warning?

from twind.

sastan avatar sastan commented on August 22, 2024

I'll start to implement this as agreed on.

from twind.

sastan avatar sastan commented on August 22, 2024

Implemented in #56

Try the Preview Package

Official releases are only available on registry.npmjs.org as twind.

This PR has been published to npm.pkg.github.com as @tw-in-js/twind@pr56.

Install/Update

Configure your NPM client (click to expand)

Adjust you .npmrc to use https://npm.pkg.github.com for @tw-in-js

@tw-in-js:registry=https://npm.pkg.github.com

Using the command line:

npm config set @tw-in-js:registry https://npm.pkg.github.com --global
# For npm
npm install --force twind@npm:@tw-in-js/twind@pr56

# For yarn - upgrade implies install
yarn upgrade twind@npm:@tw-in-js/twind@pr56

from twind.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.