To facilitate the usage of Recipe across a broader set of projects including ezCater's marketplace, a new release of Recipe was published. This release is a major version release and as such, will require migration steps for applications that currently use Recipe version 7.x or below.
The breaking changes are detailed in the Recipe release notes for version 8.0.0, but can be summarized as follows:
Applications using Recipe today that are not ready to migrate to a base font size of 16px can continue to use their current base font size by adding the new EzBaseFontSizeCompatibility component to the top-level entry point(s) for their application.
This component should be used as a sibling element to other content as shown below:
<><EzBaseFontSizeCompatibility /><EzPage><EzCard title="Card Heading"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ultrices finibus purus, inmaximus diam molestie nec. Aenean maximus eget lacus sed lobortis.</p></EzCard></EzPage></>
Applications that need to support IE11 will now require a polyfill for CSS custom properties. It is important that this polyfill is applied before defining component styles with emotion.
This typically means that the polyfill can be added at the top-level entry point(s) of your application.
with script include:
<script>if (!window.CSS || !CSS.supports('color', 'var(--a)')) {var js = document.createElement('script');js.src = 'https://cdn.jsdelivr.net/npm/css-vars-ponyfill@2';js.onload = function() {cssVars({watch: true});};document.head.appendChild(js);}</script><script src="/my-application-bundle.js"></script>
OR
with module import:
// in file src/client.js// before all other importsimport './cssVars';// in file src/cssVars.jsimport cssVars from 'css-vars-ponyfill';cssVars({watch: true});
Including the css-vars-ponyfill
and initializing it in watch mode allows the polyfill to intercept dynamically inserted styles in order to re-write them with syntax supported by browsers that would otherwise not support custom properties.
In order for the css-vars-ponyfill
to work with emotion, you must also disable emotion's speedy mode (Emotion enables speedy by default in production builds):
import {sheet} from 'emotion';sheet.speedy(false);
Emotion's speedy mode uses CSSOM APIs to insert dynamic style rules into the page. However, legacy browsers don't understand CSS custom properties and so when a rule is inserted that contains either a custom property declaration or var()
function, that declaration or function is dropped from the CSSRule.cssText
value. This behavior prevents any polyfill from rewriting those styles.
Disabling emotion's speedy mode allows emotion to insert styles as text content of a style node. This allows css-vars-ponyfill
to read the unvalidated text content directly, rather than the CSSRule.cssText
.