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

About the css prefix to css #1485

Closed
szmtcjm opened this issue May 21, 2018 · 18 comments
Closed

About the css prefix to css #1485

szmtcjm opened this issue May 21, 2018 · 18 comments

Comments

@szmtcjm
Copy link

szmtcjm commented May 21, 2018

When I use css prefix on style attributes of the html template, svelte will remove it.
Or when I use transition, svelte will not include css prefix and my page will break down in the old browsers.

@szmtcjm szmtcjm changed the title Preserve the css prefix to css About the css prefix to css May 21, 2018
@Rich-Harris
Copy link
Member

Not quite sure I follow – can you create a reproduction in the REPL? https://svelte.technology/repl

@szmtcjm
Copy link
Author

szmtcjm commented May 25, 2018

https://svelte.technology/repl?version=2.6.4&gist=6ef4f009ca9ae20c24f422d0e44ea7a3

The h1 will not show in the older browser because the transition is implemented by @Keyframe, for example:

@keyframe name {
...
}

but svelte will not include the prefixed @Keyframe:

@-webkit-keyframes  name{
...
}

So in the old browser would throw a css insert error, and not show the h1 in the REPL example. at the moment, I am not sure why it throw the error, So I guess the reason is that the the prefixed @Keyframes is not included in the animation rule.

@szmtcjm
Copy link
Author

szmtcjm commented May 25, 2018

https://svelte.technology/repl?version=2.6.4&gist=cb9db0e243ab33370295a144ad025954

This is another example which add a style attribute. The style include transform css rule transform:translateX(100px);-webkit-transform:translateX(100px). But svelte will remote -webkit-transform:translateX(100px) in the complied result.

In #558 you also had ask about browser support. So my suggestion is that

  1. Include old browser's polyfills in the complied result directly. Or
  2. A svelte-polyfill needed by old browser.

@kaisermann
Copy link
Member

kaisermann commented May 25, 2018

@szmtcjm You can do that at the svelte.preprocess step. Here's some packages that can help you with that:

And then you can just add autoprefixer to your postcss config.

@szmtcjm
Copy link
Author

szmtcjm commented May 25, 2018

@kaisermann Did you mean add preprocess for the <style> part? Yes, I can add preprocess css for the <style> part, there is no problem. But my question is the transition and style attribute in the html.

@kaisermann
Copy link
Member

@szmtcjm Oh, my bad! Actually, I've just hit the same issue with inline styles. Will update here if I find any solution for it.

About the autoprefixer thingie I commented, it seems svelte is renaming only the original @keyframes.

This:

@keyframes test {
  to {
    transform: translateX(125%)
  }
}

Generates:

@-webkit-keyframes test {}

@keyframes svelte-1erlk4x-test {
  to {
    -webkit-transform: translateX(125%);
    transform: translateX(125%)
  }
}

@szmtcjm
Copy link
Author

szmtcjm commented May 26, 2018

@kaisermann It's true. So I put autoprefixer in the css option of svelte instead of preprocess.

svelte({
  css: css => {
      postcss([autoprefixer({...})])
      .process(css.code)
      .then(result => css.write(...))
  }
})

@kaisermann
Copy link
Member

kaisermann commented May 28, 2018

@szmtcjm Good workaround! I've made a PR(#1505) to fix the prefixed @keyframes issue.

@szmtcjm
Copy link
Author

szmtcjm commented May 29, 2018

@kaisermann Awesome! But my problem have not solved.

@Conduitry
Copy link
Member

@szmtcjm The fix in 2.7.0 looks to be working to me - @keyframes blocks with known prefixes are now getting processed like regular ones are. Can you find a reproduction for your issue, preferably in the form of an example in the REPL showing the component just before Svelte gets it (not some earlier form before it goes through autoprefixer or anything).

@kaisermann
Copy link
Member

Here's the REPL. It's transforming the -webkit-transform into transform

@Conduitry
Copy link
Member

At what step is that happening? It looks to me like that is the browser's doing. In the generated code, I see setStyle(button, "-webkit-transform", "translateX(50px)");.

@szmtcjm
Copy link
Author

szmtcjm commented May 30, 2018

Oh, I see. The api CSSStyleDeclaration.setProperty(key, value); will show the unprefixed property on the style attr if it support standard . on the contrary, it will show the prefixed property.

@Conduitry
Copy link
Member

@szmtcjm Do you still have other questions or issues related to this - or can this be closed?

@szmtcjm
Copy link
Author

szmtcjm commented May 30, 2018

@Conduitry transitions which implemented by css animation also did not have @-webkit-keyframes animation-name.

@Conduitry
Copy link
Member

I'm not sure what would be a good way to handle that that wouldn't impact the vast majority of users who don't need this. The @keyframes rule is added at runtime when using transitions. caniuse reports that pretty much everyone has supported CSS animations without prefixes for a while. What browser and version is giving you trouble?

@szmtcjm
Copy link
Author

szmtcjm commented May 31, 2018

@Conduitry emm... It will throw an error when insert the @keyframes name if the browser does not support it. But the page can render in addition to did not act the transition. Maybe you can add a try {} catch() {} around the insertRule('@keyframes'). However, it does not affect if it is not added.
And this issue can be closed.

@ankitstarski
Copy link

We solved this by overriding browser's CSSStyleSheet.prototype.insertRule.

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

No branches or pull requests

5 participants