Comments (2)
So currently we cached the hooks result via
useMemo
. We looked through the source code ofmakeStyles
and find it seems doesn't cache the styles internal. Since the API can only be called in the file root level and the result is static and time consuming, why not cache the result internal?
@Leolewin I don't follow what you're caching in a React component 🤔 After the first expensive pass, a hook returned by makeStyles()
will do nothing:
griffel/packages/core/src/makeStyles.ts
Lines 30 to 60 in f134bc6
Can you please clarify WDYM?
Anyway, yes, makeStyles()
and makeResetStyles()
are expensive as any other CSS-in-JS, that's why AOT (that removes computation cost) and CSS extraction should be used it in production.
from griffel.
So currently we cached the hooks result via
useMemo
. We looked through the source code ofmakeStyles
and find it seems doesn't cache the styles internal. Since the API can only be called in the file root level and the result is static and time consuming, why not cache the result internal?@Leolewin I don't follow what you're caching in a React component 🤔 After the first expensive pass, a hook returned by
makeStyles()
will do nothing:griffel/packages/core/src/makeStyles.ts
Lines 30 to 60 in f134bc6
Can you please clarify WDYM?
Anyway, yes,
makeStyles()
andmakeResetStyles()
are expensive as any other CSS-in-JS, that's why AOT (that removes computation cost) and CSS extraction should be used it in production.
Sorry for the late reply and the misunderstanding caused by the issue description.
At very beginning, I fond the makeStyles
API has large runtime cost. So I tried to use React.useMemo
API to cache the styles returned by hook like:
const useStyles = makeStyles({ root: {color: 'red'}});
const Component = (props) => {
const styles = React.useMemo(() => useStyles());
// ...
}
But as the codes you mentioned, the large styles computation and stylesheet insertion is just happened in the first time been called. In following re-render time the styles result is get and returned directly from the closure variables. So it has almost zero runtime cost and useMemo will increase the time consuming in this case.
Thanks for your help to resolve my puzzles. Will close this issue.
from griffel.
Related Issues (20)
- Failed to override styles when selectors are grouped
- lint: add lint rule which warn unused makeStyles classes HOT 2
- vite: add support for CSS extraction HOT 2
- core: add support for fallback properties in `makeStaticStyles` HOT 3
- lint: forbid comma separated selectors in selectors HOT 2
- `shorthands.flex(1)` should produce `flex: 1 1 0%` instead of `flex: 1 1 0px` HOT 3
- Vite plugin: TypeError: griffel is not a function HOT 5
- eslint-plugin: Is not compatible with eslint 8.x HOT 2
- eslint-plugin: add no-unnecesary-shorthands rule HOT 1
- `csstype` bump to 3.1.3 causing BREAKING CHANGEs on type-level
- babel-preset: transforms don't work with native ESM packages that use `.mjs` HOT 2
- babel-preset: transforms dont work with `swc` commonjs output HOT 1
- makeResetStyles should not override makeStyles HOT 2
- core: add support for CSS shorthands HOT 6
- docs: add mergeClasses() to playground
- babel-preset: huge perf slowdown on first babel transform invoction
- core: `makeStaticStyles` to support @at-rules HOT 1
- core: hashes for @media & @container can collide HOT 1
- core: @layer is not part of property hash
- [vite-plugin] Conflict with CSS shorthands HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from griffel.