Skip to content

Commit 0c7998e

Browse files
Make custom field init() idempotent to fix stuck touch drags (microsoft#11491)
pxt's renderer re-runs field.init() on every render (the input.init() sweep in RenderInfo.measure, added in microsoft#9865 to replace the fork-era re-runnable BlockSvg.initSvg). Blockly.Field.init() is idempotent, but FieldBase and FieldCustomMelody ran onInit() unconditionally, rebuilding the field's DOM on every render. On touch, the pointerdown target implicitly captures the pointer, so destroying that element mid-drag breaks event delivery. Dragging a melody_editor shadow by its preview triggers exactly this: duplicate- on-drag forces a render at drag start, updateFieldLabel() removes the captured element, and in an iframe embed Chrome then routes the rest of the touch's events (including pointerup) to the top-level document. The gesture never ends, Blockly's touchIdentifier_ stays pinned to the dead pointer, and every subsequent touch moves the block with no way to drop it. Top-level documents seem to recover from this so we can only reproduce issues in an iframe (e.g. with controller.html). Guard init() so onInit() runs once per field, matching the Blockly.Field.init behavior. Fixes microsoft/pxt-microbit#7045
1 parent ad3e0f8 commit 0c7998e

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

‎pxtblocks/fields/field_base.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export abstract class FieldBase<U> extends Blockly.Field implements FieldCustom
4444
}
4545

4646
init() {
47+
if (this.fieldGroup_) return;
4748
super.init();
4849
this.onInit();
4950

‎pxtblocks/fields/field_melodySandbox.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class FieldCustomMelody<U extends FieldCustomOptions> extends FieldMatrix
7373
}
7474

7575
init() {
76+
if (this.fieldGroup_) return;
7677
super.init();
7778
this.onInit();
7879
}

0 commit comments

Comments
 (0)