Repository navigation
fix(AddLessonConfigureComponent): Pressing Enter adds the same lesson twice - #2348
Merged
hirokiterashima merged 2 commits intoOct 21, 2026
Conversation
… twice Pressing Enter in the lesson title field ran submit() from both the form's keydown.enter and the input's keyup handler. The second run computed the same group id, because the next id comes from the parsed project that the in-flight save has not refreshed yet, and inserted the lesson again: a duplicate id in the parent's ids and a transition from the lesson to itself. Opening the unit afterwards overflows the stack in getAllPaths() and the authoring tool falls back to the home page. Remove the keyup handler and make submit() ignore calls while a save is in flight or the title is empty, the same conditions that already disable the Submit button.
Member
|
Thanks for catching and fixing this issue @Isaries! |
Member
|
🎉 This PR is included in version 5.248.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pressing Enter in the lesson title field of the add lesson view calls
submit()twice: once from(keydown.enter)on the<form>and once from(keyup)="$event.keyCode == 13 && submit()"on the<input>. ThepreventDefault()on the keydown does not stop the keyup.submittingdisables the Submit button (the fix in #1833), butsubmit()itself never checks it, so the Enter path is not covered.The second run does not produce a second lesson. It produces a broken one:
getNextAvailableGroupId()readsthis.groupNodes, which is only rebuilt when the project is parsed again after the save. The second run therefore gets the same id as the first.addNode()replaces the node with that id, sonodesholds one lesson, butinsertNodeAfterInGroups()splices the id into the parent a second time, sogroup0.idscontains it twice.insertNodeAfterInTransitions()copies the transitions of the node it inserts after. That node already transitions to the new lesson, so the new lesson ends up transitioning to itself.Both versions are saved, the second one last. The next time the unit is opened,
parseProject()reaches the empty lesson ingetAllPaths()and recurses untilRangeError: Maximum call stack size exceeded. The authoring tool then falls back to the home page, and preview fails the same way, so the unit can no longer be opened. Copying the unit copies the broken JSON.To reproduce: open a unit in the authoring tool, choose to add a lesson, type a title and press Enter.
project.jsonnow lists the new lesson twice ingroup0.idswith a transition to itself, and reopening the unit returns to the home page.Changes
(keyup)handler on the title input. The form's(keydown.enter)already handles Enter.submit()returns early whilesubmittingis true or the form is invalid, the same conditions that disable the Submit button. Previously Enter on an empty title also added a lesson.#2349 makes
getLessonPaths()stop at such a loop, so units already saved in this state can be opened and repaired. This PR stops new ones from being created.Test
add-lesson-configure.component.spec.ts: one Enter adds one lesson, a second Enter while the save is in flight adds nothing, and Enter on an empty title adds nothing. Against the currentdevelop, the first test reportscreateGroupcalled 2 times.