@ -1,5 +1,6 @@
import { DEV } from 'esm-env' ;
import { subscribe _to _store } from '../../store/utils.js' ;
import { EMPTY _FUNC } from '../common.js' ;
import { EMPTY _FUNC , run _all } from '../common.js' ;
import { unwrap } from './render.js' ;
import { is _array } from './utils.js' ;
@ -21,7 +22,6 @@ const IS_EFFECT = EFFECT | PRE_EFFECT | RENDER_EFFECT | SYNC_EFFECT;
const FLUSH _MICROTASK = 0 ;
const FLUSH _SYNC = 1 ;
const MAX _SAFE _INT = Number . MAX _SAFE _INTEGER ;
export const UNINITIALIZED = Symbol ( ) ;
@ -457,8 +457,11 @@ function flush_queued_effects(effects) {
if ( length > 0 ) {
if ( flush _count > 100 ) {
throw new Error (
'Maximum update depth exceeded. This can happen when a reactive block or effect ' +
'repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops.'
'ERR_SVELTE_TOO_MANY_UPDATES' +
( DEV
? ': Maximum update depth exceeded. This can happen when a reactive block or effect ' +
'repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops.'
: '' )
) ;
}
flush _count ++ ;
@ -524,9 +527,7 @@ function process_task() {
is _task _queued = false ;
const tasks = current _queued _tasks . slice ( ) ;
current _queued _tasks = [ ] ;
for ( let i = 0 ; i < tasks . length ; i ++ ) {
tasks [ i ] ( ) ;
}
run _all ( tasks ) ;
}
/ * *
@ -968,9 +969,12 @@ export function set_signal_value(signal, value) {
( current _consumer . f & DERIVED ) !== 0
) {
throw new Error (
"Unsafe mutations during Svelte's render or derived phase are not permitted in runes mode. " +
'This can lead to unexpected errors and possibly cause infinite loops.\n\nIf this mutation is not meant ' +
'to be reactive do not use the "$state" rune for that declaration.'
'ERR_SVELTE_UNSAFE_MUTATION' +
( DEV
? ": Unsafe mutations during Svelte's render or derived phase are not permitted in runes mode. " +
'This can lead to unexpected errors and possibly cause infinite loops.\n\nIf this mutation is not meant ' +
'to be reactive do not use the "$state" rune for that declaration.'
: '' )
) ;
}
if (
@ -1005,10 +1009,10 @@ export function set_signal_value(signal, value) {
if ( current _effect === null && current _queued _pre _and _render _effects . length === 0 ) {
const update _callbacks = component _context ? . u ;
if ( update _callbacks != null ) {
update_callbacks . b . forEach ( /** @param {any} c */ ( c ) => c ( ) ) ;
run_all ( update_callbacks . b ) ;
const managed = managed _effect ( ( ) => {
destroy _signal ( managed ) ;
update_callbacks . a . forEach ( /** @param {any} c */ ( c ) => c ( ) ) ;
run_all ( update_callbacks . a ) ;
} ) ;
}
}
@ -1026,21 +1030,20 @@ export function destroy_signal(signal) {
const flags = signal . f ;
destroy _references ( signal ) ;
remove _consumer ( signal , 0 , true ) ;
signal . i = null ;
signal . r = null ;
signal . y = null ;
signal . x = null ;
signal . b = null ;
signal . v = /** @type {V} */ ( null ) ;
signal . d = null ;
signal . c = null ;
signal . i =
signal . r =
signal . y =
signal . x =
signal . b =
// @ts-expect-error - this is fine, since we're assigning to null to clear out a destroyed signal
signal . v =
signal . d =
signal . c =
null ;
set _signal _status ( signal , DESTROYED ) ;
if ( destroy !== null ) {
if ( is _array ( destroy ) ) {
let i ;
for ( i = 0 ; i < destroy . length ; i ++ ) {
destroy [ i ] ( ) ;
}
run _all ( destroy ) ;
} else {
destroy ( ) ;
}
@ -1146,7 +1149,10 @@ function internal_create_effect(type, init, sync, block, schedule) {
* /
export function user _effect ( init ) {
if ( current _effect === null ) {
throw new Error ( 'The Svelte $effect rune can only be used during component initialisation.' ) ;
throw new Error (
'ERR_SVELTE_ORPHAN_EFFECT' +
( DEV ? ': The Svelte $effect rune can only be used during component initialisation.' : '' )
) ;
}
const apply _component _effect _heuristics =
current _effect . f & RENDER _EFFECT &&
@ -1203,7 +1209,10 @@ export function managed_pre_effect(init, sync) {
export function pre _effect ( init ) {
if ( current _effect === null ) {
throw new Error (
'The Svelte $effect.pre rune can only be used during component initialisation.'
'ERR_SVELTE_ORPHAN_EFFECT' +
( DEV
? ': The Svelte $effect.pre rune can only be used during component initialisation.'
: '' )
) ;
}
const sync = current _effect !== null && ( current _effect . f & RENDER _EFFECT ) !== 0 ;
@ -1273,6 +1282,7 @@ export function push_destroy_fn(signal, destroy_fn) {
}
}
const STATUS _MASK = ~ ( DIRTY | MAYBE _DIRTY | CLEAN ) ;
/ * *
* @ template V
* @ param { import ( './types.js' ) . Signal < V > } signal
@ -1280,17 +1290,7 @@ export function push_destroy_fn(signal, destroy_fn) {
* @ returns { void }
* /
export function set _signal _status ( signal , status ) {
const flags = signal . f ;
if ( ( flags & status ) === 0 ) {
if ( ( flags & MAYBE _DIRTY ) !== 0 ) {
signal . f ^= MAYBE _DIRTY ;
} else if ( ( flags & CLEAN ) !== 0 ) {
signal . f ^= CLEAN ;
} else if ( ( flags & DIRTY ) !== 0 ) {
signal . f ^= DIRTY ;
}
signal . f ^= status ;
}
signal . f = ( signal . f & STATUS _MASK ) | status ;
}
/ * *
@ -1484,7 +1484,10 @@ export function safe_equal(a, b) {
export function get _or _init _context _map ( ) {
const component _context = current _component _context ;
if ( component _context === null ) {
throw new Error ( 'Context can only be used during component initialisation.' ) ;
throw new Error (
'ERR_SVELTE_ORPHAN_CONTEXT' +
( DEV ? 'Context can only be used during component initialisation.' : '' )
) ;
}
let context _map = component _context . c ;
if ( context _map === null ) {