Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,7 @@ if (DEBUG) {
moduleFor(
'Dynamic content tests: disabling a focused element',
class extends RenderingTestCase {
async '@todo a {{on "blur"}} listener may update rendered state when the element becomes disabled (GH#19287)'(
async '@test a {{on "blur"}} listener may update rendered state when the element becomes disabled (GH#19287)'(
assert
) {
let error;
Expand Down
1 change: 1 addition & 0 deletions packages/@glimmer/interfaces/lib/runtime/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface Environment {

scheduleInstallModifier(modifier: ModifierInstance): void;
scheduleUpdateModifier(modifier: ModifierInstance): void;
scheduleAttributeUpdate(update: () => void): void;

begin(): void;
commit(): void;
Expand Down
5 changes: 4 additions & 1 deletion packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,10 @@ export class UpdateDynamicAttributeOpcode implements UpdatingOpcode {
let value = valueForRef(reference);

if (initialized) {
attribute.update(value, env);
// Defer the DOM write to transaction commit: writes like `disabled`
// can synchronously dispatch events (e.g. `blur` on a focused
// element), and listeners must not run inside the render transaction.
env.scheduleAttributeUpdate(() => attribute.update(value, env));
} else {
initialized = true;
}
Expand Down
13 changes: 13 additions & 0 deletions packages/@glimmer/runtime/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const TRANSACTION: TransactionSymbol = Symbol('TRANSACTION') as Transacti
class TransactionImpl implements Transaction {
public scheduledInstallModifiers: ModifierInstance[] = [];
public scheduledUpdateModifiers: ModifierInstance[] = [];
public scheduledAttributeUpdates: (() => void)[] = [];
public createdComponents: ComponentInstanceWithCreate[] = [];
public updatedComponents: ComponentInstanceWithCreate[] = [];

Expand All @@ -47,7 +48,15 @@ class TransactionImpl implements Transaction {
this.scheduledUpdateModifiers.push(modifier);
}

scheduleAttributeUpdate(update: () => void) {
this.scheduledAttributeUpdates.push(update);
}

commit() {
for (const update of this.scheduledAttributeUpdates) {
update();
}

let { createdComponents, updatedComponents } = this;

for (const { manager, state } of createdComponents) {
Expand Down Expand Up @@ -173,6 +182,10 @@ export class EnvironmentImpl implements Environment {
}
}

scheduleAttributeUpdate(update: () => void) {
this.transaction.scheduleAttributeUpdate(update);
}

commit() {
let transaction = this.transaction;
this[TRANSACTION] = null;
Expand Down