Skip to content
Merged
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 @@ -6,7 +6,7 @@ import { create_event, delegate } from './events.js';
import { add_form_reset_listener, autofocus } from './misc.js';
import * as w from '../../warnings.js';
import { LOADING_ATTR_SYMBOL } from '#client/constants';
import { queue_idle_task } from '../task.js';
import { queue_micro_task } from '../task.js';
import { is_capture_event, is_delegated, normalize_attribute } from '../../../../utils.js';
import {
active_effect,
Expand Down Expand Up @@ -65,7 +65,7 @@ export function remove_input_defaults(input) {

// @ts-expect-error
input.__on_r = remove_defaults;
queue_idle_task(remove_defaults);
queue_micro_task(remove_defaults);
add_form_reset_listener();
}

Expand Down
32 changes: 1 addition & 31 deletions packages/svelte/src/internal/client/dom/task.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
import { run_all } from '../../shared/utils.js';
import { is_flushing_sync } from '../reactivity/batch.js';

// Fallback for when requestIdleCallback is not available
const request_idle_callback =
typeof requestIdleCallback === 'undefined'
? (/** @type {() => void} */ cb) => setTimeout(cb, 1)
: requestIdleCallback;

/** @type {Array<() => void>} */
let micro_tasks = [];

/** @type {Array<() => void>} */
let idle_tasks = [];

function run_micro_tasks() {
var tasks = micro_tasks;
micro_tasks = [];
run_all(tasks);
}

function run_idle_tasks() {
var tasks = idle_tasks;
idle_tasks = [];
run_all(tasks);
}

export function has_pending_tasks() {
return micro_tasks.length > 0 || idle_tasks.length > 0;
return micro_tasks.length > 0;
}

/**
Expand All @@ -51,26 +36,11 @@ export function queue_micro_task(fn) {
micro_tasks.push(fn);
}

/**
* @param {() => void} fn
*/
export function queue_idle_task(fn) {
if (idle_tasks.length === 0) {
request_idle_callback(run_idle_tasks);
}

idle_tasks.push(fn);
}

/**
* Synchronously run any queued tasks.
*/
export function flush_tasks() {
if (micro_tasks.length > 0) {
run_micro_tasks();
}

if (idle_tasks.length > 0) {
run_idle_tasks();
}
}
Loading