-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix stylesheet from styled components
- Loading branch information
Showing
5 changed files
with
39 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,17 @@ | ||
export { ClientOnly } | ||
import React from 'react' | ||
import { FC, ReactElement, ReactNode, useEffect, useState } from 'react' | ||
|
||
import React, { lazy, useEffect, useState, startTransition } from 'react' | ||
import type { ComponentType, ReactNode } from 'react' | ||
|
||
function ClientOnly<T>({ | ||
load, | ||
children, | ||
fallback, | ||
deps = [] | ||
}: { | ||
load: () => Promise<{ default: React.ComponentType<T> } | React.ComponentType<T>> | ||
children: (Component: React.ComponentType<T>) => ReactNode | ||
fallback: ReactNode | ||
deps?: Parameters<typeof useEffect>[1] | ||
}) { | ||
const [Component, setComponent] = useState<ComponentType<unknown> | null>(null) | ||
type Props = { | ||
children: ReactNode | ||
} | ||
export const ClientOnly: FC<Props> = ({ children }): ReactElement<any, any> | null => { | ||
const [hasMounted, setHasMounted] = useState(false) | ||
|
||
useEffect(() => { | ||
const loadComponent = () => { | ||
const Component = lazy(() => | ||
load() | ||
.then((LoadedComponent) => { | ||
return { | ||
default: () => children('default' in LoadedComponent ? LoadedComponent.default : LoadedComponent) | ||
} | ||
}) | ||
.catch((error) => { | ||
console.error('Component loading failed:', error) | ||
return { default: () => <p>Error loading component.</p> } | ||
}) | ||
) | ||
setComponent(Component) | ||
} | ||
setHasMounted(true) | ||
}, []) | ||
|
||
startTransition(() => { | ||
loadComponent() | ||
}) | ||
}, deps) | ||
if (!hasMounted) return null | ||
|
||
return Component ? <Component /> : fallback | ||
return <>{children}</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import React from 'react' | ||
import { ThemeProvider } from 'styled-components' | ||
import type { PageContext } from 'vike/types' | ||
import { themeFormatter } from '@platformbuilders/theme-toolkit' | ||
import { PageContextProvider } from './PageContextProvider.js' | ||
|
||
function PassThrough({ children }: any) { | ||
return <>{children}</> | ||
} | ||
export function PageShell({ children, pageContext }: { children: React.ReactNode; pageContext: PageContext }) { | ||
const Layout = pageContext.config.Layout || PassThrough | ||
const themeJson = themeFormatter(pageContext.config.theme) ?? {} | ||
return ( | ||
<PageContextProvider pageContext={pageContext}> | ||
<Layout theme={themeJson}>{children}</Layout> | ||
<Layout>{children}</Layout> | ||
</PageContextProvider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters