Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): render one main landmark per page

Yudhi Armyndharis26c4c9dd26c1
diff --git a/dashboard/src/main-landmark.test.ts b/dashboard/src/main-landmark.test.ts
new file mode 100644
index 000000000..fa02d4d78
--- /dev/null
+++ b/dashboard/src/main-landmark.test.ts
@@ -0,0 +1,41 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { readFileSync, readdirSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { dirname, join } from 'node:path';
+import ts from 'typescript';
+
+// Layout.tsx wraps every route in the page's one <main>. A second <main> inside a page nests landmarks,
+// which the HTML content model does not allow and which gives assistive technology two main regions
+// to jump to, the outer one around the whole page.
+
+const SRC = dirname(fileURLToPath(import.meta.url));
+
+function tsxFiles(dir: string): string[] {
+ return readdirSync(dir, { withFileTypes: true }).flatMap(entry => {
+ const full = join(dir, entry.name);
+ if (entry.isDirectory()) return tsxFiles(full);
+ return entry.name.endsWith('.tsx') ? [full] : [];
+ });
+}
+
+function mainElements(full: string): number {
+ const source = ts.createSourceFile(full, readFileSync(full, 'utf8'), ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
+ let count = 0;
+ const walk = (node: ts.Node): void => {
+ if ((ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) && node.tagName.getText() === 'main')
+ count++;
+ ts.forEachChild(node, walk);
+ };
+ walk(source);
+ return count;
+}
+
+test('only the layout renders a main element', () => {
+ const withMain = Object.fromEntries(
+ tsxFiles(SRC)
+ .map(full => [full.slice(SRC.length + 1), mainElements(full)] as const)
+ .filter(([, count]) => count > 0),
+ );
+ assert.deepEqual(withMain, { 'components/Layout.tsx': 1 });
+});
diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsx
index c8f4050b4..11a931896 100644
--- a/dashboard/src/pages/Chats.tsx
+++ b/dashboard/src/pages/Chats.tsx
@@ -1770,7 +1770,7 @@ export function Chats() {
/>
{/* RIGHT VIEW: active chat room */}
- <main className="chats-room">
+ <div className="chats-room">
{activeChat ? (
<div className="room-container">
{/* Room header */}
@@ -1990,7 +1990,7 @@ export function Chats() {
<p>{t('chats.placeholderDesc')}</p>
</div>
)}
- </main>
+ </div>
</div>
)}
diff --git a/dashboard/src/pages/Plugins.tsx b/dashboard/src/pages/Plugins.tsx
index d5bd5e213..e5f3837d5 100644
--- a/dashboard/src/pages/Plugins.tsx
+++ b/dashboard/src/pages/Plugins.tsx
@@ -930,7 +930,7 @@ export default function Plugins() {
</div>
</aside>
- <main className="plugins-main">
+ <div className="plugins-main">
<div className="plugins-grid">
{visiblePlugins.map(plugin => {
const TypeIcon = pluginTypeIcons[plugin.type as PluginType] || Puzzle;
@@ -1054,7 +1054,7 @@ export default function Plugins() {
);
})}
</div>
- </main>
+ </div>
</div>
{visiblePlugins.length === 0 && !loading && !neverLoaded && (