-
-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
205 additions
and
160 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,57 @@ | ||
import type { LoaderArgs } from './routes/+types.home'; | ||
import { | ||
dehydrate, | ||
QueryClient, | ||
HydrationBoundary, | ||
useQuery, | ||
useQueryClient, | ||
} from '@tanstack/react-query'; | ||
import { useLoaderData, useLocation } from 'react-router'; | ||
import type { MetaFunction } from 'react-router'; | ||
import { usePloneClient } from '@plone/providers'; | ||
import type { Route } from './+types/content'; | ||
import { data, useLoaderData, useLocation } from 'react-router'; | ||
import PloneClient from '@plone/client'; | ||
import App from '@plone/slots/components/App'; | ||
import { flattenToAppURL } from './utils'; | ||
import config from '@plone/registry'; | ||
|
||
export const meta: MetaFunction = () => { | ||
export const meta: Route.MetaFunction = ({ data }) => { | ||
return [ | ||
{ title: 'Plone on React Router 7' }, | ||
{ name: 'description', content: 'Welcome to Plone!' }, | ||
{ title: data?.title }, | ||
{ name: 'description', content: data?.description }, | ||
]; | ||
}; | ||
|
||
const expand = ['navroot', 'breadcrumbs', 'navigation']; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export async function loader({ params, request }: LoaderArgs) { | ||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
// With SSR, we usually want to set some default staleTime | ||
// above 0 to avoid refetching immediately on the client | ||
staleTime: 60 * 1000, | ||
}, | ||
}, | ||
}); | ||
|
||
export async function loader({ params, request }: Route.LoaderArgs) { | ||
const ploneClient = config | ||
.getUtility({ | ||
name: 'ploneClient', | ||
type: 'client', | ||
}) | ||
.method(); | ||
|
||
const { getContentQuery } = ploneClient as PloneClient; | ||
const { getContent } = ploneClient as PloneClient; | ||
|
||
const path = new URL(request.url).pathname; | ||
|
||
const path = flattenToAppURL(request.url); | ||
if ( | ||
!( | ||
/^https?:\/\//.test(path) || | ||
/^favicon.ico\/\//.test(path) || | ||
/expand/.test(path) || | ||
/^\/@@images/.test(path) || | ||
/^\/@@download/.test(path) || | ||
/^\/assets/.test(path) | ||
/\/@@images\//.test(path) || | ||
/\/@@download\//.test(path) || | ||
/^\/assets/.test(path) || | ||
/\.(css|css\.map)$/.test(path) | ||
) | ||
) { | ||
await queryClient.prefetchQuery(getContentQuery({ path, expand })); | ||
console.log('prefetching', path); | ||
try { | ||
return await getContent({ path, expand }); | ||
} catch (error) { | ||
throw data('Content Not Found', { status: 404 }); | ||
} | ||
} else { | ||
console.log('path not prefetched', path); | ||
throw data('Content Not Found', { status: 404 }); | ||
} | ||
|
||
return { dehydratedState: dehydrate(queryClient) }; | ||
} | ||
|
||
function Page() { | ||
const { getContentQuery } = usePloneClient(); | ||
const pathname = useLocation().pathname; | ||
const { data } = useQuery(getContentQuery({ path: pathname, expand })); | ||
|
||
if (!data) return 'Loading...'; | ||
return <App content={data} location={{ pathname: '/' }} />; | ||
} | ||
|
||
export default function Content() { | ||
const { dehydratedState } = useLoaderData<typeof loader>(); | ||
const queryClient = useQueryClient(); | ||
const data = useLoaderData<typeof loader>(); | ||
const pathname = useLocation().pathname; | ||
|
||
return ( | ||
<HydrationBoundary state={dehydratedState} queryClient={queryClient}> | ||
<Page /> | ||
</HydrationBoundary> | ||
); | ||
return <App content={data} location={{ pathname }} />; | ||
} |
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,8 +1,10 @@ | ||
import type { RouteConfig } from '@react-router/dev/routes'; | ||
import { index, route } from '@react-router/dev/routes'; | ||
|
||
export const routes: RouteConfig = [ | ||
const routes: RouteConfig = [ | ||
index('content.tsx', { id: 'index' }), | ||
route('ok', 'okroute.tsx', { id: 'ok' }), | ||
route('*', 'content.tsx', { id: 'splat' }), | ||
route('*', 'content.tsx', { id: 'content' }), | ||
]; | ||
|
||
export default routes; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { Config } from '@react-router/dev/config'; | ||
|
||
export default { | ||
// Config options... | ||
// Server-side render by default, to enable SPA mode set this to `false` | ||
ssr: true, | ||
} satisfies Config; |
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
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
} | ||
], | ||
"license": "MIT", | ||
"version": "1.0.0-alpha.20", | ||
"version": "1.0.0-alpha.21", | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:plone/volto.git" | ||
|
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
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 |
---|---|---|
|
@@ -60,3 +60,5 @@ docs/_build/ | |
/.python-version | ||
/.tool-versions | ||
docs/source/news | ||
|
||
.registry.loader.js |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
fix(useClipboard): Do not have a pending promise in a boolean state @nileshgulia1 |
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
Oops, something went wrong.