Skip to content

Preserve shuffled cloze order on back#253

Merged
abdnh merged 2 commits into
AnKing-VIP:masterfrom
caleblee789:codex/preserve-shuffled-cloze-order
May 4, 2026
Merged

Preserve shuffled cloze order on back#253
abdnh merged 2 commits into
AnKing-VIP:masterfrom
caleblee789:codex/preserve-shuffled-cloze-order

Conversation

@caleblee789
Copy link
Copy Markdown
Contributor

Summary

  • Persist shuffle state with stable string keys instead of DOM element object keys.
  • Preserve randomized cloze/list/image order when flipping from front to back.
  • Regenerate note type templates from src via the repo build process.

Root Cause

The shuffle map used DOM elements as object keys. Front and back card renders use separate DOMs, so the back side could miss the original shuffle map and generate or apply a different order.

Validation

  • npm run build
  • git diff --check origin/master..HEAD
  • Parsed generated shuffle scripts with new Function(...)
  • Ran a focused replay check for duplicate cloze fields sharing the same stable shuffle keys

@caleblee789
Copy link
Copy Markdown
Contributor Author

Screenshot 2026-04-26 at 2 01 08 PM Screenshot 2026-04-26 at 2 01 14 PM

Example of the issue this PR fixes.

@abdnh abdnh self-assigned this Apr 28, 2026
@abdnh
Copy link
Copy Markdown
Contributor

abdnh commented Apr 28, 2026

I can't reproduce the issue with this particular note. Can you reproduce it if you disable add-ons (I see you have AMBOSS enabled)?

In any case, this looks like a better approach and should be more reliable if there are mutations to the key element. I assume it can still fail if for example the relative order of lists is changed in the back side for some reason, but this looks like an edge case that we don't need to worry about.

@abdnh abdnh removed their assignment Apr 28, 2026
@caleblee789
Copy link
Copy Markdown
Contributor Author

This issue occurs regardless of which add-ons are enabled. Even after disabling all add-ons, it still affects some notes. It does not occur consistently across all notes, and I have not been able to identify any specific aspect of the notes that is causing it to happen or not happen. @abdnh

@caleblee789
Copy link
Copy Markdown
Contributor Author

Screenshot 2026-05-03 at 4 11 47 PM Screenshot 2026-05-03 at 4 12 50 PM

Another example with addons disabled.

@caleblee789 caleblee789 changed the title [codex] Preserve shuffled cloze order on back Preserve shuffled cloze order on back May 3, 2026
@abdnh abdnh marked this pull request as ready for review May 4, 2026 14:57
Copy link
Copy Markdown
Contributor

@abdnh abdnh left a comment

Choose a reason for hiding this comment

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

Thank you!

@abdnh abdnh merged commit 90dc90b into AnKing-VIP:master May 4, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants