Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/components/Code/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,31 @@ watch(
},
{ immediate: true },
)

// Use Nuxt's `navigateTo` for the rendered import links
function handleImportLinkNavigate() {
if (!codeRef.value) return

const anchors = codeRef.value.querySelectorAll('a.import-link')
anchors.forEach(anchor => {
// NOTE: We do not need to remove previous listeners because we re-create the entire HTML content on each html update
anchor.addEventListener('click', event => {
const href = anchor.getAttribute('href')
if (href) {
event.preventDefault()
navigateTo(href)
}
})
Comment on lines +62 to +74
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n app/components/Code/Viewer.vue | sed -n '55,85p'

Repository: npmx-dev/npmx.dev

Length of output: 1006


🏁 Script executed:

head -n 61 app/components/Code/Viewer.vue | tail -n 40

Repository: npmx-dev/npmx.dev

Length of output: 1141


🏁 Script executed:

# Check if there are any other uses of addEventListener on import-link anchors
rg "import-link" app/components/Code/Viewer.vue

Repository: npmx-dev/npmx.dev

Length of output: 204


🏁 Script executed:

head -n 30 app/components/Code/Viewer.vue

Repository: npmx-dev/npmx.dev

Length of output: 836


🏁 Script executed:

# Verify the full component structure to check Vue Composition API usage
wc -l app/components/Code/Viewer.vue && echo "---" && tail -n 30 app/components/Code/Viewer.vue

Repository: npmx-dev/npmx.dev

Length of output: 911


🏁 Script executed:

head -n 100 app/components/Code/Viewer.vue | grep -E "^import|^const.*useTemplateRef|^const.*navigateTo"

Repository: npmx-dev/npmx.dev

Length of output: 102


🏁 Script executed:

sed -n '1,15p' app/components/Code/Viewer.vue

Repository: npmx-dev/npmx.dev

Length of output: 399


Preserve modified and auxiliary link behaviour before intercepting clicks.

Currently, all anchor clicks are prevented and routed via navigateTo, which blocks ctrl/cmd‑click, middle‑click, target="_blank", and download behaviours. Add guards so normal browser behaviour is preserved for these cases.

🔧 Suggested fix
   anchors.forEach(anchor => {
     // NOTE: We do not need to remove previous listeners because we re-create the entire HTML content on each html update
     anchor.addEventListener('click', event => {
+      if (
+        event.defaultPrevented ||
+        event.button !== 0 ||
+        event.metaKey ||
+        event.ctrlKey ||
+        event.shiftKey ||
+        event.altKey ||
+        (anchor.getAttribute('target') && anchor.getAttribute('target') !== '_self') ||
+        anchor.hasAttribute('download')
+      ) {
+        return
+      }
       const href = anchor.getAttribute('href')
       if (href) {
         event.preventDefault()
         navigateTo(href)
       }
     })
   })

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sort of true I think, should we handle this? @danielroe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a fix locally. I'm not sure how merge queues work, so I'll wait for this to merge then send a follow-up PR.

})
}

watch(
() => props.html,
() => {
nextTick(handleImportLinkNavigate)
},
{ immediate: true },
)
</script>

<template>
Expand Down
Loading