move flushing_sync check inside Batch.ensure

pull/16482/head
Rich Harris 2 months ago
parent f92dfc158a
commit a6d464478a

@ -70,7 +70,7 @@ let last_scheduled_effect = null;
let is_flushing = false; let is_flushing = false;
export let flushing_sync = false; let flushing_sync = false;
export class Batch { export class Batch {
/** /**
@ -407,12 +407,12 @@ export class Batch {
return (this.#deferred ??= deferred()).promise; return (this.#deferred ??= deferred()).promise;
} }
static ensure(autoflush = true) { static ensure() {
if (current_batch === null) { if (current_batch === null) {
const batch = (current_batch = new Batch()); const batch = (current_batch = new Batch());
batches.add(current_batch); batches.add(current_batch);
if (autoflush) { if (!flushing_sync) {
Batch.enqueue(() => { Batch.enqueue(() => {
if (current_batch !== batch) { if (current_batch !== batch) {
// a flushSync happened in the meantime // a flushSync happened in the meantime
@ -455,7 +455,7 @@ export function flushSync(fn) {
try { try {
var result; var result;
const batch = Batch.ensure(false); const batch = Batch.ensure();
if (fn) { if (fn) {
batch.flush_effects(); batch.flush_effects();

@ -33,7 +33,7 @@ import * as e from '../errors.js';
import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js'; import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js';
import { get_stack, tag_proxy } from '../dev/tracing.js'; import { get_stack, tag_proxy } from '../dev/tracing.js';
import { component_context, is_runes } from '../context.js'; import { component_context, is_runes } from '../context.js';
import { Batch, flushing_sync, schedule_effect } from './batch.js'; import { Batch, schedule_effect } from './batch.js';
import { proxy } from '../proxy.js'; import { proxy } from '../proxy.js';
import { execute_derived } from './deriveds.js'; import { execute_derived } from './deriveds.js';
@ -179,7 +179,7 @@ export function internal_set(source, value) {
source.v = value; source.v = value;
const batch = Batch.ensure(!flushing_sync); var batch = Batch.ensure();
batch.capture(source, old_value); batch.capture(source, old_value);
if (DEV) { if (DEV) {

Loading…
Cancel
Save