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

Separate registry #17

Merged
merged 1 commit into from
Aug 16, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions app/layout.server.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import '@/styles/globals.css';
import AddressBar from '@/ui/AddressBar.client';
import RootStyleRegistry from '@/ui/RootStyleRegistry.client';
import nextPackageJson from 'next/package.json';
import React from 'react';
import GlobalNav from './GlobalNav.client';
Expand All @@ -11,7 +10,6 @@ export default function RootLayout({ children }: { children: any }) {
<head>
<title>Next.js Layouts and Routing Playground</title>
</head>
<RootStyleRegistry>
<body className="overflow-y-scroll bg-zinc-900">
<div className="grid grid-cols-[1fr,minmax(auto,240px),min(800px,100%),1fr] gap-x-8 py-8">
<div className="col-start-2">
Expand All @@ -34,7 +32,6 @@ export default function RootLayout({ children }: { children: any }) {
</div>
</div>
</body>
</RootStyleRegistry>
</html>
);
}
9 changes: 9 additions & 0 deletions app/styling/styled-components/layout.server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import StyledComponentsRegistry from './registry.client'

export default function Layout({ children }: { children: JSX.Element }) {
return (
<StyledComponentsRegistry>
{children}
</StyledComponentsRegistry>
)
}
31 changes: 31 additions & 0 deletions app/styling/styled-components/registry.client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { useFlushEffects } from 'next/dist/client/components/hooks-client';
import { useStyledComponentsRegistry } from '@/lib/styling';

export default function StyledComponentsRegistry({
children,
}: {
children: JSX.Element
}) {
const [StyledComponentsRegistry, styledComponentsFlushEffect] =
useStyledComponentsRegistry();

useFlushEffects(() => {
return (
<>
{styledComponentsFlushEffect()}
</>
);
});

// Only include style registry on server side for SSR
if (typeof window === 'undefined') {
return (
<StyledComponentsRegistry>
{children}
</StyledComponentsRegistry>
);
}

return children;
}
9 changes: 9 additions & 0 deletions app/styling/styled-jsx/layout.server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import StyledJsxRegistry from './registry.client'

export default function Layout({ children }: { children: JSX.Element }) {
return (
<StyledJsxRegistry>
{children}
</StyledJsxRegistry>
)
}
29 changes: 29 additions & 0 deletions app/styling/styled-jsx/registry.client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { useFlushEffects } from 'next/dist/client/components/hooks-client';
import { useStyledJsxRegistry } from '@/lib/styling';

export default function StyledJsxRegistry({
children,
}: {
children: JSX.Element;
}) {
const [StyledJsxRegistry, styledJsxFlushEffect] = useStyledJsxRegistry();

useFlushEffects(() => {
return (
<>
{styledJsxFlushEffect()}
</>
);
});

// Only include style registry on server side for SSR
if (typeof window === 'undefined') {
return (
<StyledJsxRegistry>{children}</StyledJsxRegistry>

);
}

return children;
}