From a86d70d3b2451d70068dd06baa2deb32d4881c19 Mon Sep 17 00:00:00 2001 From: Matt Quinn Date: Tue, 20 Feb 2024 16:48:47 -0500 Subject: [PATCH] PlatformIdentifier should fall back to guides' platform case style Fixes #9051 --- src/components/platformIdentifier.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/platformIdentifier.tsx b/src/components/platformIdentifier.tsx index 24cd7ced8edde..ad5df1f6350ff 100644 --- a/src/components/platformIdentifier.tsx +++ b/src/components/platformIdentifier.tsx @@ -30,13 +30,24 @@ function formatCaseStyle(style: PlatformCaseStyle | undefined, value: string) { export function PlatformIdentifier({name, platform}: Props) { const {rootNode, path} = serverContext(); - let currentPlatformOrGuide = rootNode && getCurrentPlatformOrGuide(rootNode, path); + if (!rootNode) { + return null; + } + + let currentPlatformOrGuide = getCurrentPlatformOrGuide(rootNode, path); if (!currentPlatformOrGuide && platform) { - currentPlatformOrGuide = rootNode && getPlatform(rootNode, platform); + currentPlatformOrGuide = getPlatform(rootNode, platform); } if (!currentPlatformOrGuide) { return null; } - return {formatCaseStyle(currentPlatformOrGuide.caseStyle, name)}; + // For guides, fall back to the parent platform's case style. + let caseStyle = currentPlatformOrGuide.caseStyle; + if (!caseStyle && currentPlatformOrGuide.type === 'guide') { + const parent = getPlatform(rootNode, currentPlatformOrGuide.platform); + caseStyle = parent?.caseStyle; + } + + return {formatCaseStyle(caseStyle, name)}; }