Skip to content

Emit update:interaction only on a content change - #6360

Merged
AlexVelezLl merged 3 commits into
learningequality:unstablefrom
rtibblesbot:issue-6136-3e3951
Nov 20, 2026
Merged

AlexVelezLl merged 3 commits into
learningequality:unstablefrom
rtibblesbot:issue-6136-3e3951

Conversation

@rtibblesbot

@rtibblesbot rtibblesbot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Choice, ordering, text entry, inline choice and gap match emit only on a content change, not on mount, open or identical rebuild.
  • Associate and match keep an edit made as the card closes.
  • Gap match: in Chrome, a letter typed after a space following a paragraph-end gap stays plain text.

References

Fixes #6136. Follows #6113.

Reviewer guidance

Suggested review: Full code review, then manual QA once the reviewer sets Needs QA.

Engineer review

  • Inline choice and gap match get the same emit change, though the issue names only choice, ordering and text entry.
  • Opening a Numeric card whose stored answer isn't canonical xsd:double (1.50) still emits once (interactions/textEntry/Editor.vue, mode watcher).
  • Associate and match now report an edit made as the card closes (useInteractionUpdates sync flush), which the issue did not ask for.
  • The gap match typing fix (gapMatch/GapNode.js aimsAtGap) ships here, as a maintainer asked on [QTI] Emit update:interaction only when the built interaction content changes #6136.
  • Should flush: 'sync' in QTIEditor/composables/useInteractionUpdates.js:16 be the pattern for all seven editors? Each state mutation now emits as it happens, including during the parent's patch when the questionType prop changes.
Engineer evidence

Gap match now takes over every insertText whose browser target range touches a gap, whatever the caret position (gapMatch/GapNode.js:134-137,313).

QA review

  • In Chrome, edit a choice, associate, match or gap match card (including an open distractor chip), then click Close or another card straight away. After a reload, the edit is still there.
  • On an unedited question of each type, click Edit, then Close. After a reload, it is unchanged and doesn't show Incomplete.
  • In an open card, switch between Single choice and Multiple choice, and to another type. After a reload, the new type is kept.
  • In Chrome, in a gap match passage, type a space after a gap that ends a paragraph, then a letter. The letter is passage text after the space, not part of the gap's answer.
  • In Chrome on macOS, in a gap match passage, type a word straight after a gap and let autocorrect or double-space period replace it. The replacement is applied, not appended.
Manual QA steps

QA team: question editors now save only real edits, including an edit typed just before Close. Associate and Match carry the most risk.

Requires: an exercise you can edit, on its Questions tab.

  1. Close straight after typing. Make an Associate question. Type "red" in pair 1 and click Close at once. Reload. The pair shows "red". Repeat with Match, Multiple Choice, Ordering and Inline choice.
  2. Open and close without edits. Open and close each question from item 1. Reload. Nothing changes.
  3. Text entry and Numeric. Make a Text entry question with answer "cat" and a Numeric question with "3.5". Reload, then open and close each. The answers stay. No validation message shows.
  4. Gap match passage. Requires: Chrome. Click Edit passage. After a gap that ends the paragraph, type a space and "kiwi". "kiwi" shows as plain text.

A formula changes to plain text when you close its question. This is a known problem from before this change.

Captures (7)

Close straight after typing

Step Screenshot
Associate pair saved Associate pair saved
s2-close-after-last-keystroke.webm
ordering-reorder-close-reload.webm
inline-choice-edit-option-then-close.webm

Open and close without edits

mc-open-close-untouched.webm
s4-text-entry-numeric-reopen-untouched.webm

Gap match

Step Screenshot
"kiwi" plain text "kiwi" plain text

AI usage

Claude Code wrote the watcher and specs; verified with the QTIEditor Jest suite.


Written by rtibblesbot, an LLM-based coding agent.

@rtibblesbot

🟡 Waiting for feedback

WAITING · on a reviewer
Last updated: 2026-11-20 12:04 UTC

@rtibblesbot
rtibblesbot marked this pull request as ready for review October 30, 2026 12:23
@rtibblesbot
rtibblesbot requested review from a team and leq-bot October 30, 2026 12:23

@AlexVelezLl AlexVelezLl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

After rebasing onto unstable:

  • Let's resolve the conflict in associate/__tests__/Editor.spec.js, then re-run the "type, then Close at once" QA for associate and match on top of #6357, which also changed when an open chip commits as it closes.
  • Could you please move the gap match editor (added in #6354) onto useInteractionUpdates too, with the same emit tests? It still has watch(workingInteraction, ..., { immediate: true }) in gapMatch/Editor.vue, so it emits on mount in any mode.

if (props.mode !== 'edit' || isEqual(newVal, oldVal)) return;
emit('update:interaction', newVal);
},
{ flush: 'sync' },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please carry over the comment this replaced in associate and match (each rebuild is a fresh object, so compare by value), and add a line on why this watcher has to be sync? Without it, the flush looks arbitrary and is easy to drop, which would bring back the lost edit on Close.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done: useInteractionUpdates.js now carries the compare-by-value comment from associate/match, plus one on flush: 'sync' — QTIItemEditor saves an update only while the card is in edit mode, so an edit made as the card closes has to be reported before that mode change lands.

Searched the QTIEditor tree for other watchers on workingInteraction that emit update:interaction: none left; all seven editors go through the composable.


Written by rtibblesbot, an LLM-based coding agent.

import { watch } from 'vue';
import isEqual from 'lodash/isEqual';

export function useInteractionUpdates(workingInteraction, props, emit) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please take a callback instead of emit, so each editor still shows what it emits? Something like useInteractionUpdates(workingInteraction, () => props.mode, newVal => emit('update:interaction', newVal)). That also keeps the whole props object out of the composable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done: the signature is now useInteractionUpdates(workingInteraction, getMode, onUpdate). All 7 call sites (associate, match, choice, ordering, text entry, inline choice, gap match) pass () => props.mode and newVal => emit('update:interaction', newVal).


Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot and others added 3 commits November 19, 2026 14:03
Move the update:interaction watcher into useInteractionUpdates with a
sync flush, so QTIItemEditor still reads edit mode when it lands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Choice, ordering, text entry, inline choice and gap match editors no
longer emit on mount, on entering edit mode, or on a rebuild equal by
value. Text entry still reports a stored numeric answer it canonicalizes
on opening.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Typing a space after a gap that ends a paragraph, then a letter, made
the letter a new gap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Contributor Author
  • Rebased onto unstable (with Let Save and delete act on an open answer or distractor chip #6357); no conflicts remain.
  • Gap match uses useInteractionUpdates and has the emit cases: no emit when the passage editor opens or the mode changes; an emit for an edit made as the card closes. I also added a no-emit case for an identical rebuild (whitespace typed into an empty question), which fails if the isEqual check is dropped.
  • QA ran on the rebased branch: I typed into an open chip, then clicked Close straight away, then reloaded.
    • Associate: "Yellow" typed into pair 2, item 2 is kept.
    • Match: "Woof" typed into row 2, answer 1 is kept.

Associate question after reload, response pool includes Yellow

Match question after reload, response pool includes Woof


Written by rtibblesbot, an LLM-based coding agent.

@AlexVelezLl AlexVelezLl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm!

@AlexVelezLl
AlexVelezLl merged commit 70b8383 into learningequality:unstable Nov 20, 2026
252 of 253 checks passed

Copy link
Copy Markdown
Contributor Author

Quick check on rtibblesbot's work on this PR: react 👍 helpful · 😕 mixed · 👎 not helpful. Reply with anything specific.

@rtibblesbot
rtibblesbot deleted the issue-6136-3e3951 branch November 20, 2026 14:28
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.

[QTI] Emit update:interaction only when the built interaction content changes

2 participants