From 7365cba82b50e838babe044eda63f7a44a484db1 Mon Sep 17 00:00:00 2001 From: Matt Quinn Date: Wed, 21 Feb 2024 11:47:05 -0500 Subject: [PATCH] PlatformIdentifier should fall back to guides' platform case style (#9187) 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)}; }