Comments (7)
I've managed to reproduce it using only @emotion/*
packages, and I think I found the issue:
the <Global />
component in @emotion/react
expects the data-emotion
attribute to be ${cache.key}-global ${serialised.name}
, which tss-react
doesn't have in the implementation of the CacheProvider
.
from tss-react.
Hello @yhaskell,
I appreciate your diligent investigation into this significant bug that was previously unbeknownst to me. Your provision of the reproduction repository was particularly helpful.
While I could attempt a quick fix from TSS, the optimal resolution would entail rectifying the root cause directly within the emotion repository.
To facilitate this, could I kindly ask you to revise your repository to exclusively utilize @emotion/react? You can simply replace the existing code with the following:
NextAppDirEmotionCacheProvider.tsx
"use client";
import React from "react";
import createCache from "@emotion/cache";
import { useServerInsertedHTML } from "next/navigation";
import { useState } from "react";
import { CacheProvider as DefaultCacheProvider } from "@emotion/react";
import type { Options as OptionsOfCreateCache } from "@emotion/cache";
import type { EmotionCache } from "@emotion/cache";
import type { ReactNode } from "react";
export type NextAppDirEmotionCacheProviderProps = {
/** This is the options passed to createCache() from 'import createCache from "@emotion/cache"' */
options: Omit<OptionsOfCreateCache, "insertionPoint">;
/** By default <CacheProvider /> from 'import { CacheProvider } from "@emotion/react"' */
CacheProvider?: (props: {
value: EmotionCache;
children: ReactNode;
}) => JSX.Element | null;
children: ReactNode;
};
export function NextAppDirEmotionCacheProvider(
props: NextAppDirEmotionCacheProviderProps
) {
const { options, CacheProvider = DefaultCacheProvider, children } = props;
const [{ cache, flush }] = useState(() => {
const cache = createCache(options);
cache.compat = true;
const prevInsert = cache.insert;
let inserted: string[] = [];
cache.insert = (...args) => {
const serialized = args[1];
if (cache.inserted[serialized.name] === undefined) {
inserted.push(serialized.name);
}
return prevInsert(...args);
};
const flush = () => {
const prevInserted = inserted;
inserted = [];
return prevInserted;
};
return { cache, flush };
});
useServerInsertedHTML(() => {
const names = flush();
if (names.length === 0) return null;
let styles = "";
for (const name of names) {
styles += cache.inserted[name];
}
return (
<style
key={cache.key}
data-emotion={`${cache.key} ${names.join(" ")}`}
dangerouslySetInnerHTML={{
"__html": styles
}}
/>
);
});
return <CacheProvider value={cache}>{children}</CacheProvider>;
}
GlobalStyles.tsx
"use client";
import React from "react";
import * as reactEmotion from "@emotion/react";
import type {
CSSInterpolation
} from "@emotion/serialize";
export function GlobalStyles(props: { styles: CSSInterpolation }) {
const { styles } = props;
return <reactEmotion.Global styles={reactEmotion.css(styles)} />;
}
Please ensure that only the code necessary for reproducing the bug remains. You can refer to the @emotion/react documentation here. Please steer clear of the native css prop as it presents a challenging setup.
Regrettably, I currently lack the bandwidth to undertake this task myself, but I am here to assist should you encounter any obstacles during the repository conversion.
If solely using @emotion/react resolves the issue, it's excellent news as it would imply an error on my end that I can address. Conversely, if the problem persists, we'll proceed to open an issue in the emotion repository. If a solution isn't reached within a week, I'll personally intervene to rectify the situation.
Please feel free to share any suggestions or thoughts you may have.
I extend my deepest apologies for the less-than-ideal developer experience and sincerely hope that this hasn't consumed excessive hours of your time.
Best regards,
from tss-react.
@yhaskell Cool!
That mean we can fix it quite easily.
from tss-react.
I'm trying to implement a fix and release a candidate
from tss-react.
I'm releasing 4.8.7-rc.0 right now.
If you are right in your diagnostic, it should fix it 🤞🏻
from tss-react.
I think I've implemented your suggestion correctly but it dosen't seem to work 😞
![image](https://private-user-images.githubusercontent.com/6702424/250360264-e4d0c8a9-4c58-4718-b3cc-a6b415f1b395.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTcyNDgyODAsIm5iZiI6MTcxNzI0Nzk4MCwicGF0aCI6Ii82NzAyNDI0LzI1MDM2MDI2NC1lNGQwYzhhOS00YzU4LTQ3MTgtYjNjYy1hNmI0MTVmMWIzOTUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYwMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MDFUMTMxOTQwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzAwMGFhMWVjOWQ4ZmZhNmRhYTIzOGZjMDFmOThkZTdhMjg0OTNiYzgyYzM0ZjQ3NzdjMDkyZTU4ZDE0YjkzOCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.5QX0hm9_n8ZkbvzgWJMi5xfHcydYOjGd2a99scRTy5Y)
Any idea?
from tss-react.
It's fixed, thanks a lot for your help!
from tss-react.
Related Issues (20)
- How to opt out of RTL transformation? HOT 3
- cannot Import multiple makeStyles HOT 1
- Use eslint rule to detect unused classed with imports HOT 2
- React 16.10.0 failed to install @ mui/material HOT 1
- How to use with css and styled apis. HOT 1
- yarn install with pnp mode complains about missing dependency @mui/material HOT 3
- NextJS/MUI/TSS - Cannot read properties of undefined (reading 'classes') HOT 3
- Hard reload after any file change HOT 2
- TssCacheProvider is not working when used with emotion cache and mui 5 HOT 6
- Using with Shadowed Web Components HOT 3
- Next.js: Applying augmentDocumentWithEmotionCache to document breaks AMP pages HOT 2
- The right way typing props when using withStyles HOT 3
- Invalid type for withStyles HOT 4
- Mantine integration
- Using `@import` rule within `<GlobalStyles />` component HOT 8
- `GlobalStyles` create multiple <style data-emotion="css-global">...<style> HOT 1
- Cannot read properties of undefined (reading 'length') in useGuaranteedMemo HOT 3
- MUI V5: Performance issues HOT 4
- Prop `className` did not match. HOT 7
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 tss-react.