Skip to content

Commit 951c8f1

Browse files
committed
chore: upgrade to waku 0.21.17
1 parent 17280c2 commit 951c8f1

File tree

11 files changed

+2000
-1732
lines changed

11 files changed

+2000
-1732
lines changed

.pnpmfile.cjs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
function readPackage(pkg) {
22
const versions = {
3-
react: '19.0.0-rc-7771d3a7-20240827',
4-
'react-dom': '19.0.0-rc-7771d3a7-20240827',
5-
'@types/react': '18.3.3',
6-
'@types/react-dom': '18.3.0',
7-
'react-server-dom-webpack': '19.0.0-rc-7771d3a7-20240827',
3+
react: '19.0.0',
4+
'react-dom': '19.0.0',
85
typescript: '5.4.5',
96
graphql: '16.8.1',
10-
waku: '0.21.1',
117
sharp: '0.33.1',
128
'vite-imagetools': '6.2.9',
139
};

apps/cms/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import type { AnyOperationId, OperationVariables } from '@custom/schema';
22

3+
const cache: Record<string, any> = {};
4+
35
export function createDrupalExecutor(host: string, frontendUrl: string) {
46
return async function <OperationId extends AnyOperationId>(
57
id: OperationId,
68
variables?: OperationVariables<OperationId>,
79
) {
10+
const key = `${id}:${JSON.stringify(variables)}`;
11+
if (cache[key]) {
12+
return cache[key];
13+
}
14+
815
const url = new URL(`${host}/graphql`);
916
const isMutation = id.includes('Mutation:');
1017
const publicUrl =
@@ -53,6 +60,9 @@ export function createDrupalExecutor(host: string, frontendUrl: string) {
5360
throw new Error('GraphQL error: ' + JSON.stringify(errors));
5461
}
5562
}
63+
if (!isMutation) {
64+
cache[key] = data;
65+
}
5666
return data;
5767
} catch (error) {
5868
console.error('Fetch error:', error);

apps/website/netlify/functions/strangler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ function encodeRSCUrl(inputUrl: string) {
1414

1515
function decodeRSCUrl(inputUrl: string) {
1616
const url = new URL(inputUrl, 'http://localhost');
17-
url.pathname = url.pathname.replace(/^\/RSC/, '').replace(/\.txt$/, '');
17+
url.pathname = url.pathname.replace(/^\/RSC\/R/, '').replace(/\.txt$/, '');
1818
return url;
1919
}
2020

21-
const notFoundRSC = fs.readFileSync('dist/public/RSC/404.txt').toString();
21+
const notFoundRSC = fs.readFileSync('dist/public/RSC/R/404.txt').toString();
2222

2323
export const handler = createStrangler(
2424
[
2525
{
2626
url: drupalUrl,
27-
applies: (url) => url.pathname.startsWith('/RSC/'),
27+
applies: (url) => url.pathname.startsWith('/RSC/R/'),
2828
preprocess: (event) => {
2929
// Before handling, turn the RSC url into the corresponding Drupal url.
3030
event.rawUrl = decodeRSCUrl(event.rawUrl).toString();

apps/website/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
"@custom/ui": "workspace:*",
1717
"image-dimensions": "^2.3.0",
1818
"netlify-cli": "^17.29.0",
19-
"react": "19.0.0-rc.0",
20-
"react-dom": "19.0.0-rc.0",
19+
"react": "19.0.0",
20+
"react-dom": "19.0.0",
2121
"react-error-boundary": "^4.0.13",
22-
"react-server-dom-webpack": "19.0.0-rc.0",
22+
"react-server-dom-webpack": "19.0.0",
2323
"sharp": "^0.33.4",
2424
"start-server-and-test": "^2.0.3",
2525
"tsx": "^4.7.1",
26-
"waku": "0.21.0-alpha.2"
26+
"waku": "0.21.17"
2727
},
2828
"devDependencies": {
2929
"@custom/eslint-config": "workspace:*",

apps/website/src/bridge.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,11 @@ import { Link as WakuLink, useRouter_UNSTABLE } from 'waku';
66

77
export { LocationProvider } from '@amazeelabs/bridge-waku';
88

9-
export const useLocation = createUseLocationHook(useRouter_UNSTABLE);
9+
export const useLocation = () => {
10+
const [loc, navigate] = createUseLocationHook(useRouter_UNSTABLE)();
11+
if (Array.isArray(loc.pathname)) {
12+
loc.pathname = `/${loc.pathname.join('/')}`;
13+
}
14+
return [loc, navigate];
15+
};
1016
export const Link = createLinkComponent(WakuLink);

apps/website/src/build/redirects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function writeRedirectsNetlify(config: RedirectsOutputConfig) {
140140
redirectEntry += '!';
141141
}
142142
if ([301, 302].includes(value.statusCode)) {
143-
redirectEntry += `\n/RSC${value.source}.txt /RSC${value.destination}.txt ${value.statusCode}`;
143+
redirectEntry += `\n/RSC/R${value.source}.txt /RSC/R${value.destination}.txt ${value.statusCode}`;
144144
}
145145

146146
fs.appendFileSync(`${config.outputFile}`, redirectEntry);

apps/website/src/entries.tsx

Lines changed: 80 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import { HomePage } from '@custom/ui/routes/HomePage';
1616
import { Inquiry } from '@custom/ui/routes/Inquiry';
1717
import { NotFoundPage } from '@custom/ui/routes/NotFoundPage';
1818
import { Page } from '@custom/ui/routes/Page';
19-
import React from 'react';
19+
import { Providers } from '@custom/ui/routes/Providers';
20+
import React, { PropsWithChildren } from 'react';
2021
import { createPages } from 'waku';
2122

22-
import { BrokenLinkHandler } from './broken-link-handler.js';
2323
import { ClientExecutors } from './executors-client.js';
2424
import { ServerExecutors, serverExecutors } from './executors-server.js';
2525
import { query } from './query.js';
@@ -36,58 +36,44 @@ async function queryAll<TOperation extends AnyOperationId>(
3636
);
3737
}
3838

39-
export default createPages(async ({ createPage, createLayout }) => {
40-
createLayout({
41-
render: 'static',
42-
path: '/',
43-
component: ({ children, path }) => (
44-
<BrokenLinkHandler>
45-
<LocationProvider
46-
currentLocation={{
47-
pathname: path,
48-
searchParams: new URLSearchParams(),
49-
search: '',
50-
hash: '',
51-
}}
52-
>
53-
<ServerExecutors>
54-
<ClientExecutors>
55-
<Frame alterSrc={(src) => src.replace(frontendUrl, drupalUrl)}>
56-
{children}
57-
</Frame>
58-
</ClientExecutors>
59-
</ServerExecutors>
60-
</LocationProvider>
61-
</BrokenLinkHandler>
62-
),
63-
});
64-
65-
Object.values(Locale).forEach((lang) => {
66-
createPage({
67-
render: 'static',
68-
path: `/${lang}`,
69-
component: () => <HomePage />,
70-
});
71-
72-
createPage({
73-
render: 'static',
74-
path: `/${lang}/content-hub`,
75-
component: () => <ContentHub pageSize={6} />,
76-
});
77-
78-
createPage({
79-
render: 'static',
80-
path: `/${lang}/inquiry`,
81-
component: () => <Inquiry />,
82-
});
83-
});
39+
function Layout({ children }: PropsWithChildren) {
40+
return (
41+
<ServerExecutors>
42+
<ClientExecutors>
43+
<Providers alterSrc={(src) => src.replace(frontendUrl, drupalUrl)}>
44+
{children}
45+
</Providers>
46+
</ClientExecutors>
47+
</ServerExecutors>
48+
);
49+
}
8450

85-
createPage({
86-
render: 'static',
87-
path: '/404',
88-
component: () => <NotFoundPage />,
89-
});
51+
function withPageWrapper(Component: React.FC) {
52+
return function PageWrapper({ path }: { path: string }) {
53+
return (
54+
<LocationProvider
55+
currentLocation={{
56+
pathname: path,
57+
searchParams: new URLSearchParams(),
58+
search: '',
59+
hash: '',
60+
}}
61+
>
62+
<ServerExecutors>
63+
<ClientExecutors>
64+
<Providers alterSrc={(src) => src.replace(frontendUrl, drupalUrl)}>
65+
<Frame>
66+
<Component />
67+
</Frame>
68+
</Providers>
69+
</ClientExecutors>
70+
</ServerExecutors>
71+
</LocationProvider>
72+
);
73+
};
74+
}
9075

76+
export default createPages(async ({ createPage, createLayout }) => {
9177
// Initialise a map for the homepages, since we want to exclude them from
9278
// creating a page for their internal path.
9379
const homePages = await query(HomePageQuery, {});
@@ -119,10 +105,46 @@ export default createPages(async ({ createPage, createLayout }) => {
119105
});
120106
}
121107

122-
createPage({
123-
render: 'static',
124-
path: '/[...path]',
125-
staticPaths: [...pagePaths].map((path) => path.substring(1).split('/')),
126-
component: Page,
127-
});
108+
return [
109+
createLayout({
110+
render: 'static',
111+
path: '/',
112+
component: Layout,
113+
}),
114+
115+
...Object.values(Locale)
116+
.map((lang) => [
117+
createPage({
118+
render: 'static',
119+
path: `/${lang}`,
120+
component: withPageWrapper(HomePage),
121+
}),
122+
123+
createPage({
124+
render: 'static',
125+
path: `/${lang}/content-hub`,
126+
component: () => <ContentHub pageSize={6} />,
127+
}),
128+
129+
createPage({
130+
render: 'static',
131+
path: `/${lang}/inquiry`,
132+
component: withPageWrapper(Inquiry),
133+
}),
134+
])
135+
.reduce((acc, val) => [...acc, ...val]),
136+
137+
createPage({
138+
render: 'static',
139+
path: '/404',
140+
component: withPageWrapper(NotFoundPage),
141+
}),
142+
143+
createPage({
144+
render: 'static',
145+
path: '/[...path]',
146+
staticPaths: [...pagePaths].map((path) => path.substring(1).split('/')),
147+
component: withPageWrapper(Page),
148+
}),
149+
];
128150
});

packages/schema/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"typescript": "^5.3.3"
6060
},
6161
"dependencies": {
62-
"@amazeelabs/executors": "^3.1.0",
62+
"@amazeelabs/executors": "^3.1.14",
6363
"@amazeelabs/gatsby-silverback-cloudinary": "^1.2.7",
6464
"@amazeelabs/gatsby-source-silverback": "^1.14.0",
6565
"@amazeelabs/scalars": "^1.6.13",
Lines changed: 8 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,17 @@
1-
import { ImageSettings } from '@amazeelabs/image';
2-
import { IntlProvider } from '@amazeelabs/react-intl';
3-
import { FrameQuery, Locale, Operation } from '@custom/schema';
4-
import React, { ComponentProps, PropsWithChildren } from 'react';
1+
import React, { PropsWithChildren } from 'react';
52

6-
import translationSources from '../../../build/translatables.json';
7-
import { useLocale } from '../../utils/locale';
83
import { TranslationsProvider } from '../../utils/translations';
94
import { PageTransitionWrapper } from '../Molecules/PageTransition';
105
import { Footer } from '../Organisms/Footer';
116
import { Header } from '../Organisms/Header';
127

13-
function filterByLocale(locale: Locale) {
14-
return (str: Exclude<FrameQuery['stringTranslations'], undefined>[number]) =>
15-
str.language === locale;
16-
}
17-
18-
function translationsMap(
19-
translatables: Required<FrameQuery>['stringTranslations'],
20-
) {
21-
return Object.fromEntries(
22-
translatables
23-
.filter((tr) => tr.translation)
24-
.map((tr) => [tr.source, tr.translation]),
25-
);
26-
}
27-
28-
export function Frame({
29-
children,
30-
...imageSettings
31-
}: PropsWithChildren<ComponentProps<typeof ImageSettings>>) {
32-
const locale = useLocale();
8+
export function Frame({ children }: PropsWithChildren) {
339
return (
34-
<Operation id={FrameQuery} all={true}>
35-
{(result) => {
36-
if (result.state === 'success') {
37-
const rawTranslations = result.data
38-
.map((res) => res.stringTranslations || [])
39-
.reduce((acc, val) => [...acc, ...val], []);
40-
const translations = {
41-
...translationsMap(
42-
rawTranslations?.filter(filterByLocale('en')) || [],
43-
),
44-
...translationsMap(
45-
rawTranslations?.filter(filterByLocale(locale)) || [],
46-
),
47-
};
48-
const messages = Object.fromEntries(
49-
Object.keys(translationSources).map((key) => [
50-
key,
51-
translations[
52-
translationSources[key as keyof typeof translationSources]
53-
.defaultMessage
54-
] ||
55-
translationSources[key as keyof typeof translationSources]
56-
.defaultMessage,
57-
]),
58-
);
59-
return (
60-
<ImageSettings {...imageSettings}>
61-
<IntlProvider locale={locale} messages={messages}>
62-
<TranslationsProvider>
63-
<link
64-
rel="icon"
65-
href="/images/favicon.ico"
66-
type="image/x-icon"
67-
/>
68-
<Header />
69-
<PageTransitionWrapper>{children}</PageTransitionWrapper>
70-
<Footer />
71-
</TranslationsProvider>
72-
</IntlProvider>
73-
</ImageSettings>
74-
);
75-
}
76-
}}
77-
</Operation>
10+
<TranslationsProvider>
11+
<link rel="icon" href="/images/favicon.ico" type="image/x-icon" />
12+
<Header />
13+
<PageTransitionWrapper>{children}</PageTransitionWrapper>
14+
<Footer />
15+
</TranslationsProvider>
7816
);
7917
}

0 commit comments

Comments
 (0)