1
0
mirror of synced 2025-12-22 03:16:52 -05:00

refactor clientsidehighlight (#29713)

* refactor ClientSideHighlight

* names

* names again
This commit is contained in:
Peter Bengtsson
2022-08-08 22:17:58 +02:00
committed by GitHub
parent 8ace26ee0f
commit aa727c4f70
5 changed files with 20 additions and 35 deletions

View File

@@ -1,23 +0,0 @@
import { useState, useEffect } from 'react'
export default function useLazyLoadHighlightJS(path: string) {
// If the page contains `[data-highlight]` blocks, these pages need
// syntax highlighting. But not every page needs i t, so it's conditionally
// lazy-loaded on the client.
const [lazyLoadHighlightJS, setLazyLoadHighlightJS] = useState(false)
useEffect(() => {
// It doesn't need to use querySelector because all we care about is if
// there is greater than zero of these in the DOM.
// Note! This "core selector", which determines whether to bother
// or not, needs to match what's used inside ClientSideHighlightJS.tsx
if (document.querySelector('[data-highlight]')) {
setLazyLoadHighlightJS(true)
}
// Important to depend on the current path because the first page you
// load, before any client-side navigation, might not need it, but the
// consecutive one does.
}, [path])
return lazyLoadHighlightJS
}