1- import { For , Show } from 'solid-js'
1+ import { For , Show , createMemo , createSignal } from 'solid-js'
22import { Section , SectionDescription } from '@tanstack/devtools-ui'
33import { useSeoStyles } from './use-seo-styles'
44import { pickSeverityClass } from './seo-severity'
5+ import { useLocationChanges } from './hooks/use-location-changes'
56import type { SeoSeverity } from './seo-severity'
67import type { SeoSectionSummary } from './seo-section-summary'
78
@@ -140,8 +141,18 @@ function headingTagClass(
140141
141142export function HeadingStructurePreviewSection ( ) {
142143 const styles = useSeoStyles ( )
143- const headings = extractHeadings ( )
144- const issues = validateHeadings ( headings )
144+ const [ tick , setTick ] = createSignal ( 0 )
145+
146+ useLocationChanges ( ( ) => {
147+ setTick ( ( t ) => t + 1 )
148+ } )
149+
150+ const headings = createMemo ( ( ) => {
151+ void tick ( )
152+ return extractHeadings ( )
153+ } )
154+
155+ const issues = createMemo ( ( ) => validateHeadings ( headings ( ) ) )
145156 const s = styles ( )
146157
147158 const issueBulletClass = ( sev : SeoSeverity ) =>
@@ -169,19 +180,19 @@ export function HeadingStructurePreviewSection() {
169180 < div class = { s . seoHeadingTreeHeaderRow } >
170181 < div class = { s . serpPreviewLabelFlat } > Heading tree</ div >
171182 < span class = { s . seoHeadingTreeCount } >
172- { headings . length } heading{ headings . length === 1 ? '' : 's' }
183+ { headings ( ) . length } heading{ headings ( ) . length === 1 ? '' : 's' }
173184 </ span >
174185 </ div >
175186 < Show
176- when = { headings . length > 0 }
187+ when = { headings ( ) . length > 0 }
177188 fallback = {
178189 < div class = { s . seoMissingTagsSection } >
179190 No headings found on this page.
180191 </ div >
181192 }
182193 >
183194 < ul class = { s . seoHeadingTreeList } >
184- < For each = { headings } >
195+ < For each = { headings ( ) } >
185196 { ( heading ) => (
186197 < li
187198 class = { `${ s . seoHeadingTreeItem } ${ headingIndentClass ( s , heading . level ) } ` }
@@ -205,11 +216,11 @@ export function HeadingStructurePreviewSection() {
205216 </ Show >
206217 </ div >
207218
208- < Show when = { issues . length > 0 } >
219+ < Show when = { issues ( ) . length > 0 } >
209220 < div class = { s . serpPreviewBlock } >
210221 < div class = { s . serpPreviewLabel } > Structure issues</ div >
211222 < ul class = { s . seoIssueList } >
212- < For each = { issues } >
223+ < For each = { issues ( ) } >
213224 { ( issue ) => (
214225 < li class = { s . seoIssueRow } >
215226 < span class = { issueBulletClass ( issue . severity ) } > ●</ span >
0 commit comments