@plone/aurora 1.0.0-alpha.20 → 1.0.0-alpha.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,23 @@
8
8
 
9
9
  <!-- towncrier release notes start -->
10
10
 
11
+ ## 1.0.0-alpha.22 (2026-10-30)
12
+
13
+ ### Breaking
14
+
15
+ - `REACT_ROUTER_ALLOWED_ACTION_ORIGINS` is now read when the production server starts, not when building. Set it in the environment of the running server. @sneridagh
16
+
17
+ ### Bugfix
18
+
19
+ - Fixed the interface language staying English when the project supports more languages: the i18next middleware and the client now read `config.settings.supportedLanguages` after the configuration is applied, and the client starts in the language the server detected. `app/i18n` now exports `getI18nOptions()` instead of a default options object. @sneridagh [#354](https://github.com/plone/aurora/issues/354)
20
+ - Run the production server (`pnpm start:prod`) with an Aurora server that trusts the `X-Forwarded-*` headers of proxies on private networks, instead of `react-router-serve`. Behind a proxy that terminates TLS, React Router saw the request as `http` while the browser sends an `https` origin, so every action, login included, failed with a 400. It now works for every host the site is served on, without configuration. Set `TRUST_PROXY` to change which proxies are trusted. @sneridagh
21
+
22
+ ## 1.0.0-alpha.21 (2026-10-30)
23
+
24
+ ### Feature
25
+
26
+ - The hosts allowed as action origins can be set from the environment when building (`REACT_ROUTER_ALLOWED_ACTION_ORIGINS`, comma separated, with `*`/`**` wildcards). Behind a proxy that terminates TLS, React Router sees the request as `http` while the browser sends an `https` origin, so every action, login included, failed with a 400. @sneridagh
27
+
11
28
  ## 1.0.0-alpha.20 (2026-10-29)
12
29
 
13
30
  ### Feature
@@ -1,7 +1,7 @@
1
1
  import { startTransition, StrictMode } from 'react';
2
2
  import { hydrateRoot } from 'react-dom/client';
3
3
  import { HydratedRouter } from 'react-router/dom';
4
- import i18n from './i18n';
4
+ import { getI18nOptions } from './i18n';
5
5
  import i18next from 'i18next';
6
6
  import { I18nextProvider, initReactI18next } from 'react-i18next';
7
7
  import LanguageDetector from 'i18next-browser-languagedetector';
@@ -11,18 +11,23 @@ import install from './config';
11
11
  install();
12
12
 
13
13
  async function hydrate() {
14
+ // Read the options after `install()`, which sets the supported languages
15
+ const i18n = getI18nOptions();
14
16
  await i18next
15
17
  .use(initReactI18next) // Tell i18next to use the react-i18next plugin
16
18
  .use(LanguageDetector) // Setup a client-side language detector
17
19
  .use(Backend) // Setup your backend
18
20
  .init({
19
21
  ...i18n, // spread the configuration
22
+ // The language is detected server-side with remix-i18next, and the
23
+ // layouts communicate it to the client in `<html data-locale>`. It isn't
24
+ // `<html lang>`, which is the language of the content.
25
+ lng: document.documentElement.dataset.locale,
20
26
  ns: i18n.defaultNS,
21
27
  backend: { loadPath: '/locales/{{lng}}/{{ns}}.json' },
22
28
  detection: {
23
- // Here only enable htmlTag detection, we'll detect the language only
24
- // server-side with remix-i18next, by using the `<html lang>` attribute
25
- // we can communicate to the client the language detected server-side
29
+ // Without `data-locale` (a layout that doesn't set it), fall back to
30
+ // the `<html lang>` attribute
26
31
  order: ['htmlTag'],
27
32
  // Because we only use htmlTag, there's no reason to cache the language
28
33
  // on the browser, so we disable it
package/app/i18n.ts CHANGED
@@ -1,11 +1,19 @@
1
1
  import config from '@plone/registry';
2
2
 
3
- export default {
4
- // This is the list of languages your application supports
5
- supportedLngs: config.settings.supportedLanguages ?? ['en'],
6
- // This is the language you want to use in case
7
- // if the user language is not in the supportedLngs
8
- fallbackLng: (config.settings.defaultLanguage as string | undefined) ?? 'en',
9
- // The default namespace of i18next is "translation", but you can customize it here
10
- defaultNS: 'common',
11
- };
3
+ /**
4
+ * The i18next options of the application. Call it once the configuration is
5
+ * applied, not at module load: the project and its add-ons set the supported
6
+ * languages after this module is imported.
7
+ */
8
+ export function getI18nOptions() {
9
+ return {
10
+ // This is the list of languages your application supports
11
+ supportedLngs: config.settings.supportedLanguages ?? ['en'],
12
+ // This is the language you want to use in case
13
+ // if the user language is not in the supportedLngs
14
+ fallbackLng:
15
+ (config.settings.defaultLanguage as string | undefined) ?? 'en',
16
+ // The default namespace of i18next is "translation", but you can customize it here
17
+ defaultNS: 'common',
18
+ };
19
+ }
@@ -0,0 +1,67 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2
+ import config from '@plone/registry';
3
+ import { RouterContextProvider } from 'react-router';
4
+ import { localeCookie } from '@plone/react-router';
5
+ import { getInstance, getLocale, i18nextMiddleware } from './i18next.server';
6
+
7
+ describe('i18nextMiddleware', () => {
8
+ let supportedLanguages: string[];
9
+ let defaultLanguage: unknown;
10
+
11
+ beforeEach(() => {
12
+ ({ supportedLanguages, defaultLanguage } = config.settings);
13
+ // The project's configuration is applied after this module is imported,
14
+ // like in the app, where a middleware installs it on the first request.
15
+ config.settings.defaultLanguage = 'en';
16
+ config.settings.supportedLanguages = ['en', 'de'];
17
+ });
18
+
19
+ afterEach(() => {
20
+ config.settings.defaultLanguage = defaultLanguage;
21
+ config.settings.supportedLanguages = supportedLanguages;
22
+ });
23
+
24
+ const runMiddleware = async (request: Request) => {
25
+ const context = new RouterContextProvider();
26
+ await i18nextMiddleware(
27
+ {
28
+ request,
29
+ context,
30
+ params: {},
31
+ pattern: '/',
32
+ url: new URL(request.url),
33
+ },
34
+ async () => new Response(),
35
+ );
36
+ return context;
37
+ };
38
+
39
+ it('uses the configured languages, not the ones at import time', async () => {
40
+ const context = await runMiddleware(
41
+ new Request('http://localhost:3000/?lng=de'),
42
+ );
43
+
44
+ expect(getLocale(context)).toBe('de');
45
+ expect(getInstance(context).t('cmsui.save')).toBe('Speichern');
46
+ });
47
+
48
+ it('reads the language from the locale cookie', async () => {
49
+ const context = await runMiddleware(
50
+ new Request('http://localhost:3000/', {
51
+ headers: { Cookie: await localeCookie.serialize('de') },
52
+ }),
53
+ );
54
+
55
+ expect(getLocale(context)).toBe('de');
56
+ expect(getInstance(context).t('cmsui.save')).toBe('Speichern');
57
+ });
58
+
59
+ it('falls back to the default language for unsupported ones', async () => {
60
+ const context = await runMiddleware(
61
+ new Request('http://localhost:3000/?lng=it'),
62
+ );
63
+
64
+ expect(getLocale(context)).toBe('en');
65
+ expect(getInstance(context).t('cmsui.save')).toBe('Save');
66
+ });
67
+ });
@@ -1,8 +1,9 @@
1
1
  import Backend from 'i18next-fs-backend/cjs';
2
2
  import { fileURLToPath } from 'node:url';
3
+ import type { RouterContextProvider } from 'react-router';
3
4
  import { initReactI18next } from 'react-i18next';
4
5
  import { createI18nextMiddleware } from 'remix-i18next';
5
- import i18n from './i18n'; // your i18n configuration file
6
+ import { getI18nOptions } from './i18n'; // your i18n configuration file
6
7
  import { localeCookie } from '@plone/react-router';
7
8
 
8
9
  // The add-on locales are generated into `public/locales`, which the build copies
@@ -18,24 +19,44 @@ const localesPath = fileURLToPath(
18
19
  ),
19
20
  );
20
21
 
21
- export const [i18nextMiddleware, getLocale, getInstance] =
22
- createI18nextMiddleware({
23
- detection: {
24
- supportedLanguages: i18n.supportedLngs,
25
- fallbackLanguage: i18n.fallbackLng as string,
26
- cookie: localeCookie,
27
- },
28
- // This is the configuration for i18next used
29
- // when translating messages server-side only
30
- i18next: {
31
- ...i18n,
32
- fallbackLng: i18n.fallbackLng as string,
33
- ns: i18n.defaultNS,
34
- backend: {
35
- loadPath: `${localesPath}{{lng}}/{{ns}}.json`,
22
+ let i18next: createI18nextMiddleware.ReturnType | undefined;
23
+
24
+ // Build the middleware on the first request, not at module load: the project
25
+ // and its add-ons set the supported languages after this module is imported,
26
+ // in the server configuration that the root middleware installs first.
27
+ function getI18next() {
28
+ if (!i18next) {
29
+ const i18n = getI18nOptions();
30
+ i18next = createI18nextMiddleware({
31
+ detection: {
32
+ supportedLanguages: i18n.supportedLngs,
33
+ fallbackLanguage: i18n.fallbackLng,
34
+ cookie: localeCookie,
35
+ },
36
+ // This is the configuration for i18next used
37
+ // when translating messages server-side only
38
+ i18next: {
39
+ ...i18n,
40
+ ns: i18n.defaultNS,
41
+ backend: {
42
+ loadPath: `${localesPath}{{lng}}/{{ns}}.json`,
43
+ },
36
44
  },
37
- },
38
- // The i18next plugins the middleware's instance uses.
39
- // Tip: You could pass `resources` to the `i18next` configuration and avoid a backend here
40
- plugins: [Backend, initReactI18next],
41
- });
45
+ // The i18next plugins the middleware's instance uses.
46
+ // Tip: You could pass `resources` to the `i18next` configuration and avoid a backend here
47
+ plugins: [Backend, initReactI18next],
48
+ });
49
+ }
50
+ return i18next;
51
+ }
52
+
53
+ export const i18nextMiddleware: createI18nextMiddleware.ReturnType[0] = (
54
+ args,
55
+ next,
56
+ ) => getI18next()[0](args, next);
57
+
58
+ export const getLocale = (context: Readonly<RouterContextProvider>) =>
59
+ getI18next()[1](context);
60
+
61
+ export const getInstance = (context: Readonly<RouterContextProvider>) =>
62
+ getI18next()[2](context);
package/app/root.test.tsx CHANGED
@@ -20,18 +20,10 @@ vi.mock('./i18next.server', () => ({
20
20
  async function renderStub() {
21
21
  const Stub = createRoutesStub([
22
22
  {
23
+ id: 'root',
23
24
  path: '/',
24
25
  Component: () => (
25
- <Layout
26
- params={{}}
27
- loaderData={{
28
- locale: 'en',
29
- content: {} as any,
30
- site: {} as any,
31
- isAuthenticated: false,
32
- }}
33
- matches={[{} as any]}
34
- >
26
+ <Layout>
35
27
  <p>Root Layout</p>
36
28
  </Layout>
37
29
  ),
package/app/root.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useEffect, type PropsWithChildren } from 'react';
2
- import { data, isRouteErrorResponse } from 'react-router';
2
+ import { data, isRouteErrorResponse, useRouteLoaderData } from 'react-router';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { i18nextMiddleware, getLocale } from './i18next.server';
5
5
  import type { Route } from './+types/root';
@@ -21,8 +21,10 @@ import {
21
21
  import { getClearAuthCookieHeader } from '@plone/react-router';
22
22
 
23
23
  export const middleware = [
24
- i18nextMiddleware,
24
+ // Install the configuration first: the i18next middleware reads the
25
+ // supported languages from it.
25
26
  installServerMiddleware,
27
+ i18nextMiddleware,
26
28
  PloneClientMiddleware,
27
29
  otherResources,
28
30
  getAPIResourceWithAuth,
@@ -118,11 +120,10 @@ export const handle = {
118
120
  i18n: 'common',
119
121
  };
120
122
 
121
- export function Layout({
122
- children,
123
- loaderData,
124
- }: PropsWithChildren<Route.ComponentProps>) {
125
- // loaderData can be undefined in case of an error
123
+ export function Layout({ children }: PropsWithChildren) {
124
+ // React Router doesn't pass the loader data to `Layout`, and it can be
125
+ // undefined in case of an error
126
+ const loaderData = useRouteLoaderData<RootLoader>('root');
126
127
  const locale = loaderData?.locale || 'en';
127
128
 
128
129
  // Sync the i18n instance's language to the locale detected by the loader,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@plone/aurora",
3
3
  "description": "Plone Aurora is the next-generation frontend for Plone CMS",
4
- "version": "1.0.0-alpha.20",
4
+ "version": "1.0.0-alpha.22",
5
5
  "maintainers": [
6
6
  {
7
7
  "name": "Plone Foundation",
@@ -35,26 +35,29 @@
35
35
  "@plone/agave": "1.0.0-alpha.9",
36
36
  "@plone/blocks": "1.0.0-alpha.19",
37
37
  "@plone/client": "2.0.0-alpha.10",
38
- "@plone/cmsui": "1.0.0-alpha.13",
39
- "@plone/components": "5.0.0-alpha.6",
38
+ "@plone/cmsui": "1.0.0-alpha.15",
39
+ "@plone/components": "5.0.0-alpha.7",
40
40
  "@plone/icons": "1.0.0-alpha.3",
41
- "@plone/contents": "1.0.0-alpha.4",
42
- "@plone/helpers": "2.0.0-alpha.10",
43
- "@plone/layout": "1.0.0-alpha.15",
41
+ "@plone/contents": "1.0.0-alpha.5",
42
+ "@plone/helpers": "2.0.0-alpha.11",
43
+ "@plone/layout": "1.0.0-alpha.17",
44
44
  "@plone/plate": "1.0.0-alpha.26",
45
- "@plone/publicui": "1.0.0-alpha.9",
45
+ "@plone/publicui": "1.0.0-alpha.10",
46
46
  "@plone/quanta": "1.0.0-alpha.3",
47
47
  "@plone/react-router": "2.0.0-alpha.8",
48
48
  "@plone/registry": "4.0.0-alpha.7",
49
49
  "@plone/theming": "1.0.0-alpha.10",
50
50
  "@react-router/node": "8.5.0",
51
- "@react-router/serve": "8.5.0",
51
+ "@react-router/express": "8.5.0",
52
+ "compression": "^1.8.1",
53
+ "express": "^5.2.1",
52
54
  "i18next": "^26.3.6",
53
55
  "i18next-browser-languagedetector": "^8.0.4",
54
56
  "i18next-fs-backend": "^2.6.0",
55
57
  "i18next-http-backend": "^3.0.2",
56
58
  "isbot": "^5.1.27",
57
59
  "jwt-decode": "^4.0.0",
60
+ "morgan": "^1.10.1",
58
61
  "react": "^19.2.7",
59
62
  "react-dom": "^19.2.7",
60
63
  "react-i18next": "^15.4.1",
@@ -92,7 +95,7 @@
92
95
  "start": "pnpm exec init-loaders && react-router dev",
93
96
  "build": "pnpm exec init-loaders && react-router build",
94
97
  "build:publicui": "REGISTRYCONFIG=registry-publicui.config.ts pnpm exec init-loaders && react-router build",
95
- "start:prod": "react-router-serve ./build/server/index.js",
98
+ "start:prod": "node server.js ./build/server/index.js",
96
99
  "check:ts": "react-router typegen && tsc",
97
100
  "typecheck": "react-router typegen && tsc",
98
101
  "typegen": "react-router typegen",
package/server.js ADDED
@@ -0,0 +1,135 @@
1
+ /* eslint-disable no-console */
2
+ // The production server. It does what `react-router-serve` does (compression,
3
+ // static assets, request logging and the React Router request handler), and
4
+ // also trusts the reverse proxy in front of it.
5
+ //
6
+ // Behind a proxy that terminates TLS, the request reaches this server as plain
7
+ // `http`. Without `trust proxy`, Express ignores `X-Forwarded-Proto`, the
8
+ // request URL is built as `http://…` while the browser sends an `https://…`
9
+ // `Origin`, and React Router aborts every action (login included) with a 400.
10
+ // Trusting the proxy makes the request URL match what the browser sees, for any
11
+ // host the site is served on, with nothing to configure per deployment.
12
+ //
13
+ // Usage: node server.js <server-build-path>
14
+ //
15
+ // Environment:
16
+ // - `PORT` and `HOST`: where to listen (default `3000` on all interfaces).
17
+ // - `TRUST_PROXY`: which proxies to trust, in Express's `trust proxy` syntax.
18
+ // It defaults to the private networks (`loopback, linklocal, uniquelocal`),
19
+ // where a proxy in front of a container usually connects from. Set it to
20
+ // `false` to trust no proxy.
21
+ // - `REACT_ROUTER_ALLOWED_ACTION_ORIGINS`: extra hosts allowed to submit
22
+ // actions from another origin, comma separated, with `*`/`**` wildcards.
23
+ // Read when the server starts.
24
+ import path from 'node:path';
25
+ import url from 'node:url';
26
+ import compression from 'compression';
27
+ import express from 'express';
28
+ import morgan from 'morgan';
29
+
30
+ process.env.NODE_ENV = process.env.NODE_ENV ?? 'production';
31
+ process.setSourceMapsEnabled(true);
32
+
33
+ // Imported after `NODE_ENV` is set: it loads React, which picks its development
34
+ // or production build from `NODE_ENV`, and the server build must get the same one.
35
+ const { createRequestHandler } = await import('@react-router/express');
36
+
37
+ const DEFAULT_TRUST_PROXY = 'loopback, linklocal, uniquelocal';
38
+
39
+ /**
40
+ * Parse `TRUST_PROXY` into a value for Express's `trust proxy` setting.
41
+ * @param {string | undefined} value
42
+ * @returns {boolean | number | string}
43
+ */
44
+ function parseTrustProxy(value = DEFAULT_TRUST_PROXY) {
45
+ const trimmed = value.trim();
46
+ if (trimmed === 'true') return true;
47
+ if (trimmed === 'false' || trimmed === '') return false;
48
+ if (/^\d+$/.test(trimmed)) return Number(trimmed);
49
+ return trimmed;
50
+ }
51
+
52
+ /**
53
+ * Parse a comma separated list of hosts.
54
+ * @param {string | undefined} value
55
+ * @returns {string[] | undefined}
56
+ */
57
+ function parseHosts(value) {
58
+ const hosts = value
59
+ ?.split(',')
60
+ .map((host) => host.trim())
61
+ .filter(Boolean);
62
+ return hosts?.length ? hosts : undefined;
63
+ }
64
+
65
+ /**
66
+ * The URL path the assets are served from, taken from the build's public path.
67
+ * @param {string} publicPath
68
+ */
69
+ function getExpressPath(publicPath) {
70
+ let pathname;
71
+ try {
72
+ pathname = new URL(publicPath).pathname;
73
+ } catch {
74
+ pathname = publicPath;
75
+ }
76
+ return pathname.startsWith('/') ? pathname : `/${pathname}`;
77
+ }
78
+
79
+ const buildPathArg = process.argv[2];
80
+ if (!buildPathArg) {
81
+ console.error(
82
+ 'Usage: node server.js <server-build-path>, for example node server.js build/server/index.js',
83
+ );
84
+ process.exit(1);
85
+ }
86
+
87
+ const buildPath = path.resolve(buildPathArg);
88
+ const buildModule = await import(url.pathToFileURL(buildPath).href);
89
+ const allowedActionOrigins = parseHosts(
90
+ process.env.REACT_ROUTER_ALLOWED_ACTION_ORIGINS,
91
+ );
92
+ const build = allowedActionOrigins
93
+ ? { ...buildModule, allowedActionOrigins }
94
+ : buildModule;
95
+
96
+ const assetsBuildDirectory = path.resolve(
97
+ process.cwd(),
98
+ build.assetsBuildDirectory,
99
+ );
100
+ const expressPublicPath = getExpressPath(build.publicPath);
101
+
102
+ const app = express();
103
+ app.disable('x-powered-by');
104
+ app.set('trust proxy', parseTrustProxy(process.env.TRUST_PROXY));
105
+ app.use(compression());
106
+ app.use(
107
+ path.posix.join(expressPublicPath, 'assets'),
108
+ express.static(path.join(assetsBuildDirectory, 'assets'), {
109
+ immutable: true,
110
+ maxAge: '1y',
111
+ }),
112
+ );
113
+ app.use(expressPublicPath, express.static(assetsBuildDirectory));
114
+ app.use(express.static('public', { maxAge: '1h' }));
115
+ app.use(morgan('tiny'));
116
+ app.all(
117
+ '/{*splat}',
118
+ createRequestHandler({ build, mode: process.env.NODE_ENV }),
119
+ );
120
+
121
+ const port = Number(process.env.PORT) || 3000;
122
+ const onListen = () => {
123
+ console.log(
124
+ `[aurora] listening on http://${process.env.HOST || 'localhost'}:${port}`,
125
+ );
126
+ };
127
+ const server = process.env.HOST
128
+ ? app.listen(port, process.env.HOST, onListen)
129
+ : app.listen(port, onListen);
130
+
131
+ ['SIGTERM', 'SIGINT'].forEach((signal) => {
132
+ process.once(signal, () =>
133
+ server.close((error) => error && console.error(error)),
134
+ );
135
+ });
@@ -4,7 +4,7 @@ import LanguageDetector from 'i18next-browser-languagedetector';
4
4
  import React from 'react';
5
5
  import { I18nextProvider, initReactI18next } from 'react-i18next';
6
6
 
7
- import i18n from '../app/i18n';
7
+ import { getI18nOptions } from '../app/i18n';
8
8
 
9
9
  /**
10
10
  * Use this function to render a component with the i18next provider
@@ -15,7 +15,7 @@ export async function renderWithI18n(children: React.ReactNode) {
15
15
  .use(initReactI18next)
16
16
  .use(LanguageDetector)
17
17
  .init({
18
- ...i18n,
18
+ ...getI18nOptions(),
19
19
  ns: ['common'],
20
20
  detection: {
21
21
  order: ['htmlTag'],