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: insertionFactory API for @griffel/core #407

Merged
merged 2 commits into from Jul 25, 2023

Conversation

layershifter
Copy link
Member

@layershifter layershifter commented Jul 24, 2023

This PR adds insertionFactory API to @griffel/core and related functions (makeStyles, makeResetStyles, etc.).

Every factory should return insertStyles function:

import type { GriffelInsertionFactory } from '@griffel/react'

const insertionFactory: GriffelInsertionFactory = () => {
  return function insertStyles() {
    /* do smth */
  }
}

While customization of insertion can be done by custom renderers (https://griffel.js.org/react/api/create-dom-renderer), the goal of this API is to allow customization of insertion process. For example, instead of inserting styles immediately it can be done via useInsertionEffect().

import type { GriffelInsertionFactory } from '@griffel/react'

const insertionFactory: GriffelInsertionFactory = () => {
  return function insertStyles(renderer, cssRules) {
    React.useInsertionEffect(
      () => {
        renderer.insertRules(cssRules)
      },
      [renderer, cssRules]
  }
}

Related to #40.

@github-actions
Copy link

github-actions bot commented Jul 24, 2023

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
core
__resetStyles (makeResetStyles)
207 B
174 B
254 B
184 B
47 B
10 B
core
__styles (makeStyles)
1.608 kB
772 B
1.649 kB
787 B
41 B
15 B
core
makeResetStyles (runtime)
16.886 kB
6.442 kB
16.937 kB
6.452 kB
51 B
10 B
core
makeStyles (runtime)
21.294 kB
8.04 kB
21.365 kB
8.067 kB
71 B
27 B
react
__styles
3.463 kB
1.578 kB
3.504 kB
1.593 kB
41 B
15 B
react
makeResetStyles (runtime)
18.776 kB
7.223 kB
18.816 kB
7.251 kB
40 B
28 B
react
makeStaticStyles (runtime)
8.733 kB
3.862 kB
8.791 kB
3.897 kB
58 B
35 B
react
makeStyles (runtime)
23.199 kB
8.806 kB
23.26 kB
8.836 kB
61 B
30 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
core
mergeClasses
1.82 kB
881 B
core
shorthands.padding()
4.677 kB
1.517 kB
react
__css
1.645 kB
767 B
shadow-dom
createShadowDOMRenderer
3.232 kB
1.405 kB
🤖 This report was generated against 9e29013645e396ee9af1189641936fa6670a3133

@layershifter layershifter marked this pull request as ready for review July 24, 2023 13:36
@layershifter layershifter requested a review from a team as a code owner July 24, 2023 13:36
stylesBySlots: StylesBySlots<Slots>,
factory: GriffelInsertionFactory = insertionFactory,
) {
const insertStyles = factory();
Copy link
Member

Choose a reason for hiding this comment

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

would be nice to add tests for insertion factory usage

Copy link
Member Author

Choose a reason for hiding this comment

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

I added tests for insertionFactory() itself and its connection with makeStyles 👍

@layershifter layershifter merged commit 9f7710e into microsoft:main Jul 25, 2023
4 checks passed
@layershifter layershifter deleted the feat/insertion-factory-api branch July 25, 2023 13:01
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.

None yet

2 participants