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

Some classes are being duplicated when inserting in html #15

Closed
etc-tiago opened this issue Jun 5, 2020 · 3 comments
Closed

Some classes are being duplicated when inserting in html #15

etc-tiago opened this issue Jun 5, 2020 · 3 comments
Labels
bug Something isn't working invalid This doesn't seem right

Comments

@etc-tiago
Copy link
Contributor

Description

This is not a critical bug: Some classes are being duplicated when inserting in html.

Reproduction

npx create react app

with app.jsx

import React from "react";
import { css } from "otion";
import logo from "./logo.svg";

const app = css({ textAlign: "center" });

const appHeader = css({
  backgroundColor: "#282c34",
  minHeight: "100vh",
  display: "flex",
  flexDirection: "column",
  alignItems: "center",
  justifyContent: "center",
  fontSize: "calc(10px + 2vmin)",
  color: "white",
});

const appHeaderTest = css({
  backgroundColor: "#282c34",
  fontSize: "calc(10px + 2vmin)",
  color: "white",
});

const appLogo = css({
  height: "40vmin",
  pointerEvents: "none",
  boxShadow: "0 0 10px black",
  color: "white",
});

const appLink = css({ color: "#61dafb" });

function App() {
  return (
    <div className={app}>
      <header className={appHeader}>
        <img src={logo} className={appLogo} alt="logo" />
        <p className={appHeaderTest}>
          Edit <code>src/App.js</code> and save to reload.
        </p>
        <a
          className={appLink}
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React
        </a>
      </header>
    </div>
  );
}

export default App;

the style tag:

<style id="__otion">._1azakc._1azakc{text-align:center}._13867xz._13867xz{background-color:#282c34}._1uiai01._1uiai01{min-height:100vh}._zjik7{display:flex}._qdeacm._qdeacm{flex-direction:column}._1h3rtzg._1h3rtzg{align-items:center}._f7ay7b._f7ay7b{justify-content:center}._ski4pt._ski4pt{font-size:calc(10px + 2vmin)}._1y5pc60{color:white}._y4ga4x{height:40vmin}._je8g23._je8g23{pointer-events:none}._yf6uil._yf6uil{box-shadow:0 0 10px black}._cv4vkj{color:#61dafb}</style>

Expected behavior

The first class, for example, expected it to be just:

<style id="__otion">._1azakc{text-align:center}</div>

Actual behavior

<style id="__otion">._1azakc._1azakc{text-align:center}</div>

Environment

System:

  • OS: macOS 10.15.4
  • CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  • Memory: 134.66 MB / 8.00 GB
  • Shell: 5.7.1 - /bin/zsh

Binaries:

  • Node: 12.16.3 - /usr/local/opt/node@12/bin/node
  • Yarn: 1.22.4 - /usr/local/bin/yarn
  • npm: 6.14.4 - /usr/local/opt/node@12/bin/npm
  • Watchman: 4.9.0 - /usr/local/bin/watchman

npmPackages:

  • otion: ^0.3.2 => 0.3.2
@etc-tiago etc-tiago added the bug Something isn't working label Jun 5, 2020
@kripod
Copy link
Owner

kripod commented Jun 5, 2020

Similarly to #10, this is not a bug, but a feature™ to control the precedence of CSS rules. For example, when paddingTop: 20 and padding: 10 are both specified inside css(), then the former adjustment should take precedence over the latter. Every padding will become 10px, except for the top one, which remains 20px even though it's declared before the other rule.

If you're interested in a discussion about potential improvements, please refer to #1.

@kripod kripod closed this as completed Jun 5, 2020
@kripod kripod added the invalid This doesn't seem right label Jun 5, 2020
@kripod
Copy link
Owner

kripod commented Jul 22, 2020

Version 0.4.0 addresses this issue by managing precedences without class name repetition. Please give it a try and get back to me if you notice any issues 😊

@etc-tiago
Copy link
Contributor Author

Now it is much better, there is a significant reduction in the size of the styles on the page. Thank you for your time and effort in developing this solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants