-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Animation keyframes are not localized, breaking other styled components expected behavior #2871
Comments
That's because you didn't use our |
@Andarist, thanks for the quick response. Indeed, I have used However, the end-game here is to enable downstream "style artisans" (pseudo developers) to write standard css text blocks, inclusive of keyframes using the exact same syntax as a From trying different things with If I cannot figure out a way to adhere to css file-like syntax and localized it entirely, it becomes much more complex to educate style artisans in how to break up different pieces of their css into JSON key/values, as well as much more complicated on the back-end. I do not mind doing necessary work on the back-end once I find a way to achieve this. As an alternative, I have tried Is there any way to use Here is a css block example I am hoping to fully localize, and then map names in/out:
Your thoughts and help with this is sincerely appreciated. |
It's not possible at the moment - it has been designed to use this separate I think though that what you want is very much doable with Emotion and Stylis. It will come at some extra parsing cost, but I don't think that this is a problem in this case - and that extra cost could probably be even avoided if you would mimick our serialized styles object. The idea is to do this:
|
That's pretty much the trajectory I am on now. I am recursively parsing through the compiled object:
While realizing I have a slightly deeper knowledge of Likely a RegEx to be applied to both the
If you have any thoughts on how to match all animation references to the keyframes, I welcome your idea(s). If not, go ahead an close this issue as I think there is enough on the topic for the community to learn from. A full css file (text block) Thank you @Andarist! |
@n8sabes From a strictly stylis perspective, consider the following input: const AST = compile(`
a {
b {
@keyframes spin { from { color: red; } to { color: blue; } }
animation: spin 4s forwards;
}
}
`) That would produces AST nodes for the the animation Such that the above would convert both references to spin to Beyond that finding the animation name in the short hand syntax is ruling out valid options like the valid keywords(forwards, backwards, etc) that can appear, numbers etc, anything else being a valid animation name, previous version of stylis had this logic if you want to dig in, it was in the prefixer logic as it related to animation-name and keyframes. |
Thank you @thysultan. There are pros and cons to the example. It seems the example syntax would require the semi-technical-non-developer "style artisans" to be educated on special nesting/formatting syntax vs straight forward css file syntax. This pushes me toward the brute force localized naming approach, as much as I don't want to do this. You have good points that I am going to explore further, agreed on reserved keyword mapping issues I had not yet considered, and will find time to look at some (legacy?) Community Compliment -- I have truly enjoyed working with |
@thysultan, can you tell me what version of |
@Andarist, @thysultan, Et al. What do you think of this to replace all possible usage syntaxes of animation name with the localized name when traversing the RegEx Sandobx of the following regular expression
Code Sandbox of the following code
The above regex + code selects the following usage variations, taking into consideration preamble and post amble characters.
|
The approach looks OK to me |
@Andarist and @thysultan, I've written a couple helper functions that leverage both As always, thanks for the help. Closing this issue. |
Animation
@keyframes
inv11.10.0
are not localized, breaking other styled component's expected behavior.The expected behavior is for the style to use the localized keyframes name:
animation-m9qj3z
, but instead the keyframes are written to the global scope and used across all components that might use the same name -- in this casespin
.Bug Sandbox Example
compile
output of stylis?My implementation dynamically loads components with their respective styles at runtime. Therefore, I cannot ensure all 3rd party libraries won't reuse common animation keyframe names such as
spin
,fade
, etc.Example code:
The text was updated successfully, but these errors were encountered: