Skip to content

Commit 877977e

Browse files
committed
default CCIP sidebar to EVM on initial load
1 parent e737bfe commit 877977e

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/components/LeftSidebar/RecursiveSidebar.astro

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@ function shouldExpandSection(item: SectionContent, currentPage: string): boolean
192192
return langVisible && chainVisible
193193
}
194194

195+
/**
196+
* Detects chain type from URL path
197+
* This ensures consistent behavior even before the store initializes
198+
*/
199+
function detectChainFromPath(pathname: string): string | null {
200+
if (/\/(evm|ethereum)(\/|$)/i.test(pathname)) return "evm"
201+
if (/\/(svm|solana)(\/|$)/i.test(pathname)) return "solana"
202+
if (/\/aptos(\/|$)/i.test(pathname)) return "aptos"
203+
return null
204+
}
205+
195206
/**
196207
* Filters sidebar items based on selected SDK language
197208
* - Hides items with data-sdk-lang that don't match current selection
@@ -211,11 +222,26 @@ function shouldExpandSection(item: SectionContent, currentPage: string): boolean
211222
}
212223

213224
// Get current chain type if chain filtering is active (for CCIP section)
225+
// Priority: URL path detection → localStorage → default (EVM)
214226
let currentChain: string | undefined
215227
try {
216-
const chainStore = localStorage.getItem("chainlink-docs-chain-type")
217-
if (chainStore) {
218-
currentChain = chainStore
228+
// Priority 1: Detect from URL (e.g., /ccip/getting-started/svm → "solana")
229+
const detectedChain = detectChainFromPath(window.location.pathname)
230+
if (detectedChain) {
231+
currentChain = detectedChain
232+
} else {
233+
// Priority 2: Read from localStorage
234+
const chainStore = localStorage.getItem("chainlink-docs-chain-type")
235+
if (chainStore) {
236+
currentChain = chainStore
237+
} else {
238+
// Priority 3: Default to EVM if we're in a section that uses chain filtering
239+
// Check if any items in the sidebar have chain type attributes
240+
const hasChainTypes = document.querySelector("[data-chain-types]:not([data-chain-types='universal'])")
241+
if (hasChainTypes) {
242+
currentChain = "evm" // Default chain type
243+
}
244+
}
219245
}
220246
} catch {
221247
// Chain filtering not active in this section

0 commit comments

Comments
 (0)