Skip to content

Don't allow content to get mutated when creating glossary-plain#2274

Merged
Kuuuube merged 2 commits intoyomidevs:masterfrom
Kuuuube:clean-plain-results
Dec 29, 2025
Merged

Don't allow content to get mutated when creating glossary-plain#2274
Kuuuube merged 2 commits intoyomidevs:masterfrom
Kuuuube:clean-plain-results

Conversation

@Kuuuube
Copy link
Copy Markdown
Member

@Kuuuube Kuuuube commented Dec 28, 2025

Fixes #2270

#2261 was fixing the wrong problem. Reverting that change in 9283255.

The real problem was this part failing to do anything due to content getting cleared out: https://github.com/Kuuuube/yomitan/blob/fa28f9a5163e39c9054eac1bd3e13fba3e4d643e/ext/js/templates/anki-template-renderer.js#L773-L776.

I don't really understand how the original code did not have this same issue (tell me how this doesn't mutate content ???):

/**
 * @param {import('structured-content.js').Content[]} content
 * @returns {import('structured-content.js').Content[]}
 */
_extractGlossaryDataOld(content) {
    /** @type {import('structured-content.js').Content[]} */
    const glossaryContentQueue = [];
    const structuredContentQueue = content;
    while (structuredContentQueue.length > 0) {
        const structuredContent = structuredContentQueue.shift();
        if (Array.isArray(structuredContent)) {
            structuredContentQueue.push(...structuredContent);
        } else if (typeof structuredContent === 'object' && structuredContent.content) {
            // @ts-expect-error - Checking if `data` exists
            if (structuredContent.data?.content === 'glossary') {
                glossaryContentQueue.push(structuredContent);
                continue;
            }
            structuredContentQueue.push(structuredContent.content);
        }
    }

    return glossaryContentQueue;
}

But for whatever reason this works and now with the recursive version it doesn't. Both use shift just the same and assigning content to another variable beforehand in the current version does nothing (as is expected since it's setting a reference). Only thing I can think is JS breaks the ref if it gets too deep into the recursion.

Regardless, this doesn't actually need a shift anymore since the recursive version never pushes anything back into the original array.

@Kuuuube Kuuuube requested a review from a team as a code owner December 28, 2025 22:07
@Kuuuube Kuuuube added kind/bug The issue or PR is regarding a bug area/anki The issue or PR is related to Anki integration regression This issue or PR is related to a regression labels Dec 28, 2025
@Kuuuube Kuuuube added this pull request to the merge queue Dec 29, 2025
Merged via the queue into yomidevs:master with commit 65dae60 Dec 29, 2025
19 of 25 checks passed
@Kuuuube Kuuuube deleted the clean-plain-results branch December 29, 2025 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/anki The issue or PR is related to Anki integration kind/bug The issue or PR is regarding a bug regression This issue or PR is related to a regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anki flashcard config: glossary-plain and glossary-plain-no-dictionary fields output issue

2 participants