Skip to content

Commit 2fc42a1

Browse files
committed
fix(devtools): handle empty JSON-LD script content gracefully
This commit updates the JSON-LD analysis function to ensure that it handles cases where the script content is null or empty. By using optional chaining and providing a default empty string, the function now avoids potential errors and improves robustness in processing JSON-LD scripts.
1 parent 5d5de5f commit 2fc42a1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

packages/devtools/src/tabs/seo-tab/json-ld-preview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ function analyzeJsonLdScripts(): Array<JsonLdEntry> {
330330
)
331331

332332
return scripts.map((script, index) => {
333-
const raw = script.textContent.trim()
334-
if (!raw) {
333+
const raw = script.textContent?.trim() || ''
334+
if (raw.length === 0) {
335335
return {
336336
id: `jsonld-${index}`,
337337
raw,

packages/devtools/src/tabs/seo-tab/links-preview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type LinkRow = {
2424
function classifyLink(anchor: HTMLAnchorElement): LinkRow {
2525
const href = anchor.getAttribute('href')?.trim() || ''
2626
const text =
27-
anchor.textContent.trim() ||
27+
anchor.textContent?.trim() ||
2828
anchor.getAttribute('aria-label')?.trim() ||
2929
anchor.getAttribute('title')?.trim() ||
3030
''

0 commit comments

Comments
 (0)