leave cx as it is but extend sheet.insert to cache styles into a globally accessible window cache when running in "extraction" mode (window.__STYLE_SYSTEM_EXTRACTION_MODE)
where we cannot extract
calls to css inside of functions
styled components with interpolated props functions
run the output webpack bundle(s) in extraction mode
in JSDom environment set window.__STYLE_SYSTEM_EXTRACTION_MODE = true then run output webpack bundle(s)
serialize the resulting window.__STYLE_SYSTEM_INSERTION_CACHE__ into a separate LOAD FIRST bundle that pushes the result to a window.__STYLE_SYSTEM_WARM_CACHE__
when the compiler runs the first time, it checks window.__STYLE_SYSTEM_WARM_CACHE__ and if it exists, call native sheet.insert for each value in the warmed cache.
replace top level calls to css with assignments to the generated classname
const focusedStyle = css`color: blue`;
becomes
const focusedStyle = "prefix-123abc";
How to do this with styled? Do we do something like the following
const Styled = styled.div`color: blue`;
becomes
const $$Styled_Styles = css`color: blue`; // => this gets replaced with just the generated classname of course
const $$Styled_Component = core.div;
const Styled = (props) => {
const className = cx($$Styled_Styles, props.className); // how do we get cx into scope?
return createComponent( // how do we get createComponent into scope?
$$Styled_Component,
Object.assign({}, props, { className })
);
}
cx
as it is but extendsheet.insert
to cache styles into a globally accessible window cache when running in "extraction" mode (window.__STYLE_SYSTEM_EXTRACTION_MODE
)css
and then pass them through cxbuild time extraction script
window.__STYLE_SYSTEM_EXTRACTION_MODE = true
then run output webpack bundle(s)window.__STYLE_SYSTEM_INSERTION_CACHE__
into a separate LOAD FIRST bundle that pushes the result to awindow.__STYLE_SYSTEM_WARM_CACHE__
window.__STYLE_SYSTEM_WARM_CACHE__
and if it exists, call nativesheet.insert
for each value in the warmed cache.Basically... in
createCompiler
:replace top level calls to
css
with assignments to the generated classnamebecomes
How to do this with
styled
? Do we do something like the followingbecomes
and
becomes
ehhhhhh not sure what to do here...
css
css
andstyled
:thinking:css
andstyled
that would have happened at runtime and making them happen