Skip to content

Commit

Permalink
[RR7] Update to latest RR7 and conventions, fix index page (#6589)
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh authored Jan 14, 2025
1 parent 1c88feb commit 7c2a6de
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 107 deletions.
14 changes: 9 additions & 5 deletions apps/rr7/app/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type { MetaFunction } from 'react-router';
import { usePloneClient } from '@plone/providers';
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 = () => {
Expand Down Expand Up @@ -44,18 +43,23 @@ export async function loader({ params, request }: LoaderArgs) {

const { getContentQuery } = ploneClient as PloneClient;

const path = flattenToAppURL(request.url);
const path = new URL(request.url).pathname;

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)
)
) {
console.log('prefetching', path);
await queryClient.prefetchQuery(getContentQuery({ path, expand }));
} else {
console.log('path not prefetched', path);
}

return { dehydratedState: dehydrate(queryClient) };
Expand Down
4 changes: 3 additions & 1 deletion apps/rr7/app/routes.ts
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' }),
];

export default routes;
22 changes: 11 additions & 11 deletions apps/rr7/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
"typegen": "react-router typegen"
},
"dependencies": {
"@react-router/node": "7.0.0-pre.4",
"@react-router/serve": "7.0.0-pre.4",
"@tanstack/react-query": "^5.59.0",
"@tanstack/react-query-devtools": "^5.59.0",
"isbot": "^5.1.17",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router": "7.0.0-pre.4"
},
"devDependencies": {
"@plone/blocks": "workspace:*",
"@plone/client": "workspace:*",
"@plone/components": "workspace:*",
"@plone/providers": "workspace:*",
"@plone/registry": "workspace:*",
"@plone/slots": "workspace:*",
"@plone/theming": "workspace:*",
"@react-router/dev": "7.0.0-pre.4",
"@react-router/node": "7.1.1",
"@react-router/serve": "7.1.1",
"@tanstack/react-query": "^5.59.0",
"@tanstack/react-query-devtools": "^5.59.0",
"isbot": "^5.1.17",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router": "7.1.1"
},
"devDependencies": {
"@react-router/dev": "7.1.1",
"@types/react": "^18.3.9",
"@types/react-dom": "^18.3.0",
"typescript": "^5.6.3",
Expand Down
7 changes: 7 additions & 0 deletions apps/rr7/react-router.config.ts
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;
11 changes: 2 additions & 9 deletions apps/rr7/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ const prodServerName =
: '';

export default defineConfig({
plugins: [
reactRouter({
// Server-side render by default, to enable SPA mode set this to `false`
ssr: true,
}),
tsconfigPaths(),
PloneRegistryVitePlugin(),
],
plugins: [PloneRegistryVitePlugin(), reactRouter(), tsconfigPaths()],
server: {
port: 3000,
proxy: {
Expand All @@ -29,7 +22,7 @@ export default defineConfig({
secure: false,
}),
rewrite: (path) => {
console.log(path);
console.log('rewritten path', path);
return path.replace('/++api++', '');
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/slots/components/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Logo = (props: SlotComponentProps) => {
name: 'translation',
type: 'factory',
}).method;

const navRootPath = content['@components'].navroot?.navroot?.['@id'] || '/';
const site = content['@components'].site;
const siteTitle = site?.['plone.site_title'] || '';
Expand Down
2 changes: 2 additions & 0 deletions packages/volto/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ docs/_build/
/.python-version
/.tool-versions
docs/source/news

.registry.loader.js
Loading

0 comments on commit 7c2a6de

Please sign in to comment.