@graphcommerce/next-ui 7.1.0-canary.56 → 7.1.0-canary.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 7.1.0-canary.58
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2121](https://github.com/graphcommerce-org/graphcommerce/pull/2121) [`a5da6ffc8`](https://github.com/graphcommerce-org/graphcommerce/commit/a5da6ffc8be359e93c7bde986134f7162aae13b9) - Change the critical css injection location to be in the head instead of `<style>` tags in the body. It has a number of negative consequences, such as the famous "flash of unstyled content" (FOUC) and the re-paint and re-layout required. ([@paales](https://github.com/paales))
8
+
9
+ ## 7.1.0-canary.57
10
+
3
11
  ## 7.1.0-canary.56
4
12
 
5
13
  ### Patch Changes
@@ -1,9 +1,8 @@
1
1
  import { GlobalStyles } from '@mui/material'
2
2
  import { LazyMotion } from 'framer-motion'
3
+ import { EmotionProvider, EmotionProviderProps } from '../Styles/EmotionProvider'
3
4
 
4
- export type GraphCommerceProviderProps = {
5
- children: React.ReactNode
6
- }
5
+ export type CssAndFramerMotionProviderProps = EmotionProviderProps
7
6
 
8
7
  /**
9
8
  * For [@emotion/core](https://emotion.sh/docs/introduction) and
@@ -12,22 +11,25 @@ export type GraphCommerceProviderProps = {
12
11
  * - Wrapps the app to lazily load framer-motion.
13
12
  * - Wrapps the app to have Emotion CSS styles
14
13
  */
15
- export function CssAndFramerMotionProvider({ children }: GraphCommerceProviderProps) {
14
+ export function CssAndFramerMotionProvider(props: CssAndFramerMotionProviderProps) {
15
+ const { children, emotionCache } = props
16
16
  return (
17
- <LazyMotion features={async () => (await import('./framerFeatures')).default} strict>
18
- {children}
19
- <GlobalStyles
20
- styles={{
21
- ':root': {
22
- '--client-size-y': '100vh',
23
- '--client-size-x': '100vw',
24
- '@supports(height: 100dvh)': {
25
- '--client-size-y': '100dvh',
26
- '--client-size-x': '100dvw',
17
+ <EmotionProvider emotionCache={emotionCache}>
18
+ <LazyMotion features={async () => (await import('./framerFeatures')).default} strict>
19
+ {children}
20
+ <GlobalStyles
21
+ styles={{
22
+ ':root': {
23
+ '--client-size-y': '100vh',
24
+ '--client-size-x': '100vw',
25
+ '@supports(height: 100dvh)': {
26
+ '--client-size-y': '100dvh',
27
+ '--client-size-x': '100dvw',
28
+ },
27
29
  },
28
- },
29
- }}
30
- />
31
- </LazyMotion>
30
+ }}
31
+ />
32
+ </LazyMotion>
33
+ </EmotionProvider>
32
34
  )
33
35
  }
@@ -1,14 +1,14 @@
1
- import createCache from '@emotion/cache'
2
1
  import type { EmotionCache } from '@emotion/cache'
3
2
  import { CacheProvider } from '@emotion/react'
3
+ import { createEmotionCache } from './createEmotionCache'
4
4
 
5
- let muiCache: EmotionCache | undefined
6
- export const createMuiCache = () => {
7
- muiCache = createCache({ key: 'mui' })
8
- return muiCache
9
- }
5
+ export type EmotionProviderProps = { children?: React.ReactNode; emotionCache?: EmotionCache }
6
+
7
+ const clientSideEmotionCache = createEmotionCache()
10
8
 
11
9
  /** Provider that is supposed to be used in your `pages/_app.tsx` */
12
- export function EmotionProvider({ children }: { children: React.ReactNode }) {
13
- return <CacheProvider value={muiCache ?? createMuiCache()}>{children}</CacheProvider>
10
+ export function EmotionProvider(props: EmotionProviderProps) {
11
+ const { children, emotionCache = clientSideEmotionCache } = props
12
+
13
+ return <CacheProvider value={emotionCache}>{children}</CacheProvider>
14
14
  }
@@ -0,0 +1,14 @@
1
+ import createCache from '@emotion/cache'
2
+
3
+ export const createEmotionCache = () => {
4
+ let insertionPoint: HTMLElement | undefined
5
+
6
+ if (typeof window !== 'undefined') {
7
+ const emotionInsertionPoint = document.querySelector<HTMLMetaElement>(
8
+ 'meta[name="emotion-insertion-point"]',
9
+ )
10
+ insertionPoint = emotionInsertionPoint ?? undefined
11
+ }
12
+
13
+ return createCache({ key: 'mui-style', insertionPoint })
14
+ }
@@ -1,36 +1,46 @@
1
1
  import type { EmotionJSX } from '@emotion/react/types/jsx-namespace'
2
2
  import createEmotionServer from '@emotion/server/create-instance'
3
3
  // eslint-disable-next-line @next/next/no-document-import-in-page
4
+ import { AppType } from 'next/app'
4
5
  import type NextDocument from 'next/document'
5
6
  // eslint-disable-next-line @next/next/no-document-import-in-page
6
7
  import type { DocumentContext, DocumentInitialProps } from 'next/document'
7
- import { createMuiCache } from './EmotionProvider'
8
+ import { EmotionProviderProps } from './EmotionProvider'
9
+ import { createEmotionCache } from './createEmotionCache'
8
10
 
9
11
  export type EmotionCacheProps = { emotionStyleTags: EmotionJSX.Element[] }
10
12
 
11
13
  export function withEmotionCache(Document: typeof NextDocument): typeof NextDocument {
12
14
  return class DocumentWithEmotionCache extends Document {
13
15
  static async getInitialProps(ctx: DocumentContext) {
14
- const emotionServer = createEmotionServer(createMuiCache())
15
- const initialProps = await Document.getInitialProps(ctx)
16
+ const cache = createEmotionCache()
17
+ const emotionServer = createEmotionServer(cache)
18
+
19
+ const originalRenderPage = ctx.renderPage
20
+ ctx.renderPage = () =>
21
+ originalRenderPage({
22
+ enhanceApp:
23
+ (App: React.ComponentType<React.ComponentProps<AppType> & EmotionProviderProps>) =>
24
+ (props) => <App emotionCache={cache} {...props} />,
25
+ })
16
26
 
17
- const emotionStyleTags = emotionServer
18
- .extractCriticalToChunks(initialProps.html)
19
- .styles.filter(({ css }) => css !== '')
20
- .map((style) => (
21
- <style
22
- data-emotion={`${style.key} ${style.ids.join(' ')}`}
23
- key={style.key}
24
- // eslint-disable-next-line react/no-danger
25
- dangerouslySetInnerHTML={{ __html: style.css }}
26
- />
27
- ))
27
+ const initialProps = await Document.getInitialProps(ctx)
28
+ // This is important. It prevents Emotion to render invalid HTML.
29
+ // See https://github.com/mui/material-ui/issues/26561#issuecomment-855286153
30
+ const emotionStyles = emotionServer.extractCriticalToChunks(initialProps.html)
31
+ const emotionStyleTags = emotionStyles.styles.map((style) => (
32
+ <style
33
+ data-emotion={`${style.key} ${style.ids.join(' ')}`}
34
+ key={style.key}
35
+ // eslint-disable-next-line react/no-danger
36
+ dangerouslySetInnerHTML={{ __html: style.css }}
37
+ />
38
+ ))
28
39
 
29
- const props: DocumentInitialProps & EmotionCacheProps = {
40
+ return {
30
41
  ...initialProps,
31
42
  emotionStyleTags,
32
43
  }
33
- return props
34
44
  }
35
45
  }
36
46
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/next-ui",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "7.1.0-canary.56",
5
+ "version": "7.1.0-canary.58",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -26,13 +26,13 @@
26
26
  "typescript": "5.2.2"
27
27
  },
28
28
  "peerDependencies": {
29
- "@graphcommerce/eslint-config-pwa": "^7.1.0-canary.56",
30
- "@graphcommerce/framer-next-pages": "^7.1.0-canary.56",
31
- "@graphcommerce/framer-scroller": "^7.1.0-canary.56",
32
- "@graphcommerce/framer-utils": "^7.1.0-canary.56",
33
- "@graphcommerce/image": "^7.1.0-canary.56",
34
- "@graphcommerce/prettier-config-pwa": "^7.1.0-canary.56",
35
- "@graphcommerce/typescript-config-pwa": "^7.1.0-canary.56",
29
+ "@graphcommerce/eslint-config-pwa": "^7.1.0-canary.58",
30
+ "@graphcommerce/framer-next-pages": "^7.1.0-canary.58",
31
+ "@graphcommerce/framer-scroller": "^7.1.0-canary.58",
32
+ "@graphcommerce/framer-utils": "^7.1.0-canary.58",
33
+ "@graphcommerce/image": "^7.1.0-canary.58",
34
+ "@graphcommerce/prettier-config-pwa": "^7.1.0-canary.58",
35
+ "@graphcommerce/typescript-config-pwa": "^7.1.0-canary.58",
36
36
  "@lingui/core": "^4.2.1",
37
37
  "@lingui/macro": "^4.2.1",
38
38
  "@lingui/react": "^4.2.1",