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

chore(examples/theme-ui): fix styling #3949

Merged
merged 5 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@
- sandulat
- sbernheim4
- schpet
- scottybrown
- sdavids
- sean-roberts
- sebz
Expand Down
6 changes: 2 additions & 4 deletions examples/theme-ui/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CacheProvider } from "@emotion/react";
import { RemixBrowser } from "@remix-run/react";
import type { FunctionComponent } from "react";
import { useState } from "react";
import { useCallback, useState } from "react";
import { hydrate } from "react-dom";

import { ClientStyleContext } from "./styles/context";
Expand All @@ -10,9 +10,7 @@ import { createEmotionCache } from "./styles/createEmotionCache";
const ClientCacheProvider: FunctionComponent = ({ children }) => {
const [cache, setCache] = useState(createEmotionCache());

const reset = () => {
setCache(createEmotionCache());
};
const reset = useCallback(() => setCache(createEmotionCache()), []);

return (
<ClientStyleContext.Provider value={{ reset }}>
Expand Down
14 changes: 3 additions & 11 deletions examples/theme-ui/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,12 @@ const Document = withEmotionCache(
({ children }: DocumentProps, emotionCache) => {
const serverStyleData = useContext(ServerStyleContext);
const clientStyleData = useContext(ClientStyleContext);
const resetClientStyleData = clientStyleData?.reset;

// Only executed on client
useEffect(() => {
// re-link sheet container
emotionCache.sheet.container = document.head;
// re-inject tags
const tags = emotionCache.sheet.tags;
emotionCache.sheet.flush();
tags.forEach((tag) => {
(emotionCache.sheet as any)._insertTag(tag);
});
// reset cache to reapply global styles
clientStyleData?.reset();
}, [clientStyleData, emotionCache.sheet]);
resetClientStyleData();
}, [resetClientStyleData]);

return (
<html lang="en">
Expand Down
2 changes: 2 additions & 0 deletions examples/theme-ui/app/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/** @jsx jsx */
import { jsx } from "@theme-ui/core";
import { Link } from "@remix-run/react";

export default function Index() {
Expand Down
2 changes: 2 additions & 0 deletions examples/theme-ui/app/routes/jokes.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/** @jsx jsx */
import { jsx } from "@theme-ui/core";
import { Link } from "@remix-run/react";

export default function Jokes() {
Expand Down