fix: doc links show grey when target missing, not always blue

The resolution check returned true when the document list was empty
(before storage was populated), making all links appear blue. Now
returns false when no documents are loaded, correctly showing grey
for unresolved targets.

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Jinwoo-H
2026-05-01 03:17:33 -04:00
co-authored by Orca
parent dd80c54ef4
commit de21d8dc37
@@ -16,7 +16,7 @@ const docLinkAutoConvertKey = new PluginKey('docLinkAutoConvert')
function isDocLinkResolved(target: string, documents: MarkdownDocument[]): boolean {
if (documents.length === 0) {
return true
return false
}
const index = createMarkdownDocumentIndex(documents)
return resolveMarkdownDocLink(target, index).status === 'resolved'
@@ -82,8 +82,11 @@ export const MarkdownDocLink = Node.create({
addNodeView() {
const storage = this.storage as { documents: MarkdownDocument[] }
return ({ node }: { node: { type: { name: string }; attrs: { target?: string } } }) => {
const target = typeof node.attrs.target === 'string' ? node.attrs.target : ''
return ({ node }: { node: { type: { name: string }; attrs: Record<string, unknown> } }) => {
const getTarget = (n: { attrs: Record<string, unknown> }): string =>
typeof n.attrs.target === 'string' ? n.attrs.target : ''
const target = getTarget(node)
const dom = document.createElement('span')
dom.setAttribute('data-doc-link-target', target)
dom.setAttribute('contenteditable', 'false')
@@ -100,12 +103,14 @@ export const MarkdownDocLink = Node.create({
return {
dom,
update: (updatedNode) => {
// Why: this fires on every transaction, including the no-op dispatched
// when the document list changes in storage. Re-checking resolution
// here keeps the blue/grey styling current without a full re-render.
update: (updatedNode: { type: { name: string }; attrs: Record<string, unknown> }) => {
if (updatedNode.type.name !== 'markdownDocLink') {
return false
}
const newTarget =
typeof updatedNode.attrs.target === 'string' ? updatedNode.attrs.target : ''
const newTarget = getTarget(updatedNode)
dom.setAttribute('data-doc-link-target', newTarget)
dom.textContent = newTarget
applyResolutionClass(newTarget)