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

Preserve Custom Properties #268

Merged

Conversation

jonathantneal
Copy link
Contributor

@jonathantneal jonathantneal commented Oct 8, 2020

This changes the internal hyphenAndVendorPrefixCssProp function to a prevent isVendorPrefixed from returning a false positive when evaluating a custom property. It also adds a custom property test that would currently fail.

Current Behavior

A custom property like --whatever is transformed into ---whatever.

This is caused by a vendor prefix check that checks for uppercase letters and falsely matches dashes.

const isVendorPrefixed = cssProp[0] === cssProp[0].toUpperCase()

// ( `-` === `-`.toUpperCase() ) === true // 😿🧻

Proposed Behavior

A custom property like --whatever remains --whatever.

The vendor prefix check would explicitly check for an uppercase letter.

const isVendorPrefixed = /^[A-Z]/.test(cssProp);

// /^[A-Z]/.test(`-`) === false // 😸 🎉 

Resolves #267

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 8, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit cc1d517:

Sandbox Source
Stitches CI: Next.js Configuration
Stitches CI: CRA Configuration

@jonathantneal jonathantneal marked this pull request as ready for review October 8, 2020 13:35
@jonathantneal jonathantneal requested review from hadihallak and peduarte and removed request for hadihallak October 8, 2020 13:55
Copy link
Contributor

@peduarte peduarte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 😍

@peduarte
Copy link
Contributor

peduarte commented Oct 8, 2020

@jonathantneal I added the following test case in the react package, just to validate it works well there too:

test.only('Renders basic component with css variable', () => {
	const H1 = styled('h1', {
		'--test': 'oioi',
		fontSize: 18,
	});

	expect(renderer.create(<H1 className="hi">hello world</H1>).toJSON()).toMatchSnapshot();
});

And I get the following snapshot:

exports[`styled Renders basic component with css variable 1`] = `
{
  "orderedAppliedStyles": [
    "._eoEivG {font-size: 18px;}",
    "._idMeSv {---test: oioi;}"
  ],
  "props": {
    "className": "hi _idMeSv _eoEivG scid-dWnSgo"
  },
  "children": [
    "hello world"
  ]
}
`;

Note how the CSS Variable still contains 3 dashes ("._idMeSv {---test: oioi;}")


UPDATE: It works after rebuilding core! 🤕

@peduarte peduarte merged commit 2b0a1e2 into stitchesjs:canary Oct 8, 2020
@jonathantneal jonathantneal deleted the jn.preserve-custom-properties branch October 8, 2020 14:47
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

Successfully merging this pull request may close these issues.

Custom Properties Prefixed With Additional Hyphen
2 participants