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

feat(Vanilla Extract): as a future replacement of jss #561

Merged
merged 54 commits into from
Nov 8, 2022

Conversation

atabel
Copy link
Contributor

@atabel atabel commented Oct 25, 2022

Tasks

To do:

  • Make storybook work
  • Make playroom work
  • Setup vanilla extract build and generate mistica.css file
  • Make jest unit test work with vanilla extract
  • Configure eslint import/extensions rule to work with .css.ts extensions
    • configured locally, but we should consider moving that config to @telefonica/eslint-config
  • Vendor prefixes
  • Automatic box-sizing: border-box
  • Figure out the best way to work with media queries
    • media queries are now static and not configurable. I've deprecated ThemeConfig['mediaQueries'] and will be removed in future versions
    • We were using ThemeConfig['mediaQueries'] configuration in Playroom for two things: override desktopOrTabletMinHeight to 0 to not fallback to mobile break point when the bottom code panel is shown, and for the PreviewTools forceMobile and forceDesktop props. Those props are heavily used in Mistica docs in brand factory site. To support these use cases the solution I've found is making two additional Playroom static builds served in /playroom-desktop and /playroom-mobile which use custom media query breakpoints (see playroom.config.js changes). The downside is that this will increase the preview deployments time. A future improvement could be to only make these additional playroom builds when deploying to prod, and skip them in PR previews.
  • Make ssr tests work

Nice to have:

  • Make storybook run with vite instead of webpack?

Release plan

We can release a first version with all the setup and then migrate component by component in future PRs

Major version?

Some breaking changes:

  • Once we remove jss completely from mistica we'll need to remove the createUseStyles function, so we'll need a major version for sure. But this isn't done in this PR yet and we can do it in future PRs once we have migrated all components
  • To use components that use vanilla extract, the app that uses mistica needs to include/serve the new css/mistica.css file. This is a breaking change. We could find a way to mitigate this by inlining the css in the js or something. It isn't the more performance solution but could be a good transient solution that doesn't force us to release a major version yet

The plan:

  • Merge this branch in a first minor version:
    • the generated Vanilla Extract css will be injected in js and rendered in a <style> tag by ThemeContextProvider.
    • Deprecate ThemeConfig['mediaQueries'] (see details above).
    • Deprecate createUseStyles
  • In future PRs, migrate all the components to VE
  • Write docs with a migration path for apps using createUseStyles from mistica
  • In a major release, remove JSS from mistica.

@github-actions
Copy link

github-actions bot commented Oct 25, 2022

Size stats

master this branch diff
Total JS 8.43 MB 4.03 MB -4.4 MB
JS without icons 905 kB 451 kB -454 kB
Lib overhead 160 kB 155 kB -5.07 kB
Lib overhead (gzip) 0 B 47.3 kB +47.3 kB

@github-actions
Copy link

github-actions bot commented Oct 26, 2022

Deploy preview for mistica-web ready!

✅ Preview
https://mistica-2tehy5vuv-tuentisre.vercel.app

Built with commit 1185096.
This pull request is being automatically deployed with vercel-action

@github-actions
Copy link

github-actions bot commented Oct 26, 2022

Accessibility report
✔️ No issues found

ℹ️ You can run this locally by executing yarn audit-accessibility.

@@ -18,6 +18,7 @@ storybook-static/
.vercel
src/generated/mistica-icons/index.tsx.txt
reports
css/mistica.css
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this file is generated by yarn build

className={classes.avatar}
role="img"
aria-label={ariaLabel ?? initials}
style={{width: size, height: size, color: textColor, background: backgroundColor}}
Copy link
Contributor

Choose a reason for hiding this comment

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

so now we will use more and more inline styles to support things like 'isInverse' colors right? or could we create a common set of styles with sprinkles for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can use sprinkles when possible (as an alternative to inline styles), but only when dynamic values are available in our sprinkles definitions. For example, if a component receives a prop color, we can use it with sprinkles if the color is one of the skin, but if the color prop accepts any string then we need to use inline styles


const sizes = [0, 2, 4, 8, 12, 16, 24, 32, 40, 48, 56, 64, 72, 80] as const;

const commonProperties = defineProperties({
Copy link
Contributor

Choose a reason for hiding this comment

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

from the documentation

 conditions: {
    mobile: {},
    tablet: { '@media': 'screen and (min-width: 768px)' },
    desktop: { '@media': 'screen and (min-width: 1024px)' }
  }

i think this is also interesting

Copy link
Contributor Author

@atabel atabel Oct 27, 2022

Choose a reason for hiding this comment

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

I still need to figure out how to work with mediaqueries, because until now mistica media queries have been configurable with context, but I don't know how to make them configurable and at the same time be able to use them in vanilla extract / sprinkles. (css doesn't allow variables in @media 😞 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a TODO to the PR list

@atabel atabel requested review from pladaria and brtbrt October 27, 2022 06:40
@sergivillar
Copy link
Contributor

really nice, two questions

  • how vanilla-extract solve the issue of hash classnames generation in SSR? we had issues with this in JSS
  • what will happen with the currently createUserStyles?

@atabel
Copy link
Contributor Author

atabel commented Oct 27, 2022

really nice, two questions

  • how vanilla-extract solve the issue of hash classnames generation in SSR? we had issues with this in JSS

Classnames are generated at build time, so there should never be hydration missmatches

  • what will happen with the currently createUserStyles?

As said in "Release plan", once we migrate all components to VS, we'll remove JSS from mistica, so the apps using mistica which were using createUseStyles will need to use JSS directly or migrate to other style solution.

Comment on lines +4 to +36
const getMediaQueriesConfig = () => {
const impossibleSize = 999999;

if (process.env.FORCE_MOBILE) {
return {
tabletMinWidth: impossibleSize,
desktopMinWidth: impossibleSize,
largeDesktopMinWidth: impossibleSize,
desktopOrTabletMinHeight: impossibleSize,
};
}
if (process.env.FORCE_DESKTOP) {
return {
tabletMinWidth: 0,
desktopMinWidth: 0,
largeDesktopMinWidth: impossibleSize,
desktopOrTabletMinHeight: 0,
};
}
return {
desktopOrTabletMinHeight: 0,
};
};

const getOutputPath = () => {
if (process.env.FORCE_MOBILE) {
return './public/playroom-mobile/';
}
if (process.env.FORCE_DESKTOP) {
return './public/playroom-desktop/';
}
return './public/playroom/';
};
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this file could include a comment explaining the reasons of this, as stated in the PR description

@sergivillar
Copy link
Contributor

where is done the double build that you talked about in the description? I cant see it @atabel

@atabel
Copy link
Contributor Author

atabel commented Nov 3, 2022

where is done the double build that you talked about in the description? I cant see it @atabel

see package.json vercel-build script

@@ -15,6 +15,7 @@ export {
ServerSideStyles,
} from './jss';

export {vars as skinVars} from './skins/skin-contract.css';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Export vars (skin colors) to be usable by apps using Vanilla Extract

vite.config.js Outdated
Comment on lines 12 to 13
// Change .css.js files to something else so that they don't get re-processed by consumer apps using vanilla extract too
fileNames: ({name}) => `${name.replace(/\.css$/, '.css.vanilla')}.js`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Vanilla Extract Next plugin applies to node_modules too, so it tries to re-process mistica files (which are already compiled by mistica build) and result in errors. With this change, we make those files invisible for the Next plugin in apps using mistica and VE (zeus, for example).

Copy link
Member

Choose a reason for hiding this comment

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

perhaps a better name would be .css.mistica

react(),
vanillaExtractPlugin(),
noBundlePlugin({
// Change .css.js files to something else so that they don't get re-processed by consumer apps using vanilla extract too
Copy link
Contributor

Choose a reason for hiding this comment

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

this is because VE process all files ended in css? ir is because of vite?

@atabel atabel changed the title Introduce vanilla extract as a future replacement of jss in mistica feat(Vanilla Extract): as a future replacement of jss Nov 8, 2022
@atabel atabel merged commit 8e54a95 into master Nov 8, 2022
@atabel atabel deleted the atoledano-vanilla branch November 8, 2022 10:43
tuentisre pushed a commit that referenced this pull request Nov 10, 2022
# [12.9.0](v12.8.0...v12.9.0) (2022-11-10)

### Bug Fixes

* **Cards:** close button ([#576](#576)) ([4c27059](4c27059))
* **playroom:** PreviewTools tabs in desktop ([#574](#574)) ([76f39cc](76f39cc))

### Features

* **Vanilla Extract:** as a future replacement of jss ([#561](#561)) ([8e54a95](8e54a95))
@tuentisre
Copy link
Collaborator

🎉 This PR is included in version 12.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants