Skip to content

Commit ea2a2cb

Browse files
committed
Fix legacy link text display by prioritizing direct text property
- Add support for direct 'text' property in LinkNode getTextFromNode function - Update linkValidator to prioritize 'text' property when creating children array - Update getLinkDisplayText to check for direct text property first - This fixes legacy links that have text property but were showing page IDs instead of titles
1 parent 06a2728 commit ea2a2cb

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

app/components/editor/LinkNode.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,14 @@ const LinkNode: React.FC<LinkNodeProps> = ({ node, canEdit = false, isEditing =
191191
// NOTE: Compound links are now handled separately in the rendering logic,
192192
// so this function only extracts the base text without compound formatting
193193

194-
// CRITICAL FIX: Properly extract custom text from children array first
194+
// CRITICAL FIX: Check for direct text property first (legacy links)
195+
// This handles legacy links that have a direct "text" property
196+
if (node.text && node.text.trim() && node.text !== 'Link' && node.text !== 'Page Link') {
197+
console.log('LEGACY_TEXT_DEBUG: Found direct text property:', node.text);
198+
return node.text.trim();
199+
}
200+
201+
// CRITICAL FIX: Properly extract custom text from children array
195202
// This is the most important source of custom text that users configure
196203
if (node.children && Array.isArray(node.children) && node.children.length > 0) {
197204
// Concatenate all text from children to handle custom text properly
@@ -207,35 +214,35 @@ const LinkNode: React.FC<LinkNodeProps> = ({ node, canEdit = false, isEditing =
207214
}
208215
}
209216

210-
// 2. Check for explicit displayText property (backup for custom text)
217+
// 3. Check for explicit displayText property (backup for custom text)
211218
if (node.displayText && node.displayText !== 'Link' && node.displayText.trim()) {
212219
console.log('CUSTOM_TEXT_DEBUG: Found displayText:', node.displayText);
213220
return node.displayText;
214221
}
215222

216-
// 3. Check for pageTitle (for page links without custom text)
223+
// 4. Check for pageTitle (for page links without custom text)
217224
if (node.pageTitle && node.pageTitle !== 'Link') {
218225
return node.pageTitle;
219226
}
220227

221-
// 4. Check for originalPageTitle
228+
// 5. Check for originalPageTitle
222229
if (node.originalPageTitle && node.originalPageTitle !== 'Link') {
223230
return node.originalPageTitle;
224231
}
225232

226-
// 5. Use the standardized utility function as fallback
233+
// 6. Use the standardized utility function as fallback
227234
const utilityText = getLinkDisplayText(node);
228235
if (utilityText && utilityText !== 'Link') {
229236
return utilityText;
230237
}
231238

232-
// 6. Check for text in data property
239+
// 7. Check for text in data property
233240
if (node.data && typeof node.data === 'object') {
234241
if (node.data.text && node.data.text.trim()) return node.data.text;
235242
if (node.data.displayText && node.data.displayText.trim()) return node.data.displayText;
236243
}
237244

238-
// 7. Use appropriate fallbacks based on link type
245+
// 8. Use appropriate fallbacks based on link type
239246
if (isExternal && href) return href;
240247
if (pageId) return pageId.replace(/-/g, ' ');
241248

app/utils/linkValidator.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ export function validateLink(linkData) {
7272

7373
// CRITICAL FIX: Ensure children array exists and has at least one text node
7474
if (!link.children || !Array.isArray(link.children) || link.children.length === 0) {
75-
// Create a default text node if none exists
76-
const displayText = link.displayText || link.text || (link.pageTitle ? link.pageTitle : 'Link');
75+
// Create a default text node if none exists - prioritize direct text property for legacy links
76+
const displayText = link.text || link.displayText || (link.pageTitle ? link.pageTitle : 'Link');
7777
link.children = [{ text: displayText }];
7878
}
7979

@@ -315,6 +315,11 @@ export function validateLink(linkData) {
315315
export function getLinkDisplayText(linkData) {
316316
if (!linkData) return 'Link';
317317

318+
// CRITICAL FIX: Check for direct text property first (legacy links)
319+
if (linkData.text) {
320+
return linkData.text;
321+
}
322+
318323
// First check for pageTitle as it's the most reliable source for page links
319324
if (linkData.pageTitle) {
320325
return linkData.pageTitle;

0 commit comments

Comments
 (0)