fix: update glossary.mdx to use encoded key when searching the DOM

fix: remove stale entries in the DOM if they become null
This commit is contained in:
Ashvin-Sr
2025-12-05 16:03:21 -05:00
parent d55789c6eb
commit a8a5c36142

View File

@@ -30,7 +30,8 @@ export const GlossaryContent = () => {
const scrollToRow = (topic, rowKey) => {
const topicId = encodeURIComponent(topic);
const row = tableRefs.current[topicId]?.[rowKey];
const encRowKey = encodeURIComponent(rowKey);
const row = tableRefs.current[topicId]?.[encRowKey];
if (row) {
row.scrollIntoView({ behavior: 'smooth', block: 'center' });
row.classList.add('table-row-highlight');
@@ -86,9 +87,15 @@ export const GlossaryContent = () => {
return {
ref: (node) => {
if (!tableRefs.current[topicId]) tableRefs.current[topicId] = {};
if (node) {
if (!tableRefs.current[topicId]) tableRefs.current[topicId] = {};
tableRefs.current[topicId][record.key] = node;
} else {
// cleanup stale reference when row unmounts
delete tableRefs.current[topicId][record.key];
if (Object.keys(tableRefs.current[topicId]).length === 0) {
delete tableRefs.current[topicId];
}
}
},
};