Skip to content

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

Open
rtibblesbot wants to merge 3 commits into
learningequality:unstablefrom
rtibblesbot:issue-6136-3e3951
Open

rtibblesbot wants to merge 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 stop emitting on mount, on opening, or on identical rebuilds.
  • Associate and match keep an edit made as the card closes.
  • All seven editors share one synchronous watcher.
  • Gap match: a letter typed after a space following a paragraph-end gap no longer becomes a new gap in Chrome.

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 content changes. Associate and Match keep an edit made as a chip closes. Chip editors carry the most risk.

Requires: an exercise with each question type below. Open its Questions tab and click Edit on a question.

  1. Gap match distractors. Click Add distractor, type and click Save. Edit a chip and click Save. Edit another chip and click its delete (×) button. Reload. One Save closes the editor. Delete removes only that chip. The edits stay.
  2. Associate and Match chips. Edit a chip, then click a different chip. Edit it, then click the blank area left of Save. Edit a chip, then click outside the chip list. Reload. The other chip opens. The open chip closes and does not open again. The edits stay.
  3. Chip toolbar and keyboard. In an open chip, open the Normal menu, then click Distractors (optional). Open and close the image dialog. Tab to a closed chip and press Enter or Space. The chip stays open. Enter and Space open the chip.
  4. Image in a chip. Insert an image, click Save and reload. Report if the image shows.
  5. Other question types. Edit Choice, Inline choice and Ordering, click Close at once, and reload. The edits stay. In Text entry, clear the answer. Incomplete shows.

Look out for:

  • In Chrome, in Gap match, type a space after an end-of-paragraph gap, then a letter. Look out for a new gap.
Captures (18)

Gap match distractors

Step Screenshot
Deletes done Deletes done
Reloaded Reloaded
gapmatch-distractors-save-delete-add.webm

Associate and Match chips

Step Screenshot
Other chip opens Other chip opens
Own padding closes Own padding closes
Outside click closes Outside click closes
Reloaded Reloaded

Chip toolbar, image dialog, keyboard

Step Screenshot
Menu dismissed Menu dismissed
Image dialog closed Image dialog closed
chip-menu-image-keyboard.webm

Other question types

Step Screenshot
Choice reloaded Choice reloaded
Ordering reloaded Ordering reloaded
Text entry cleared Text entry cleared
Text entry reloaded Text entry reloaded
Numeric 0.50 opened Numeric 0.50 opened
Inline choice reloaded Inline choice reloaded
s1-single-choice-edit-text-and-correct.webm
s2-choice-net-identical-then-real-edit-before-close.webm

AI usage

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


Written by rtibblesbot, an LLM-based coding agent.

@rtibblesbot

🟢 Updating PR

Last updated: 2026-11-20 11:16 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.

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