@@ -8,13 +8,18 @@ import {
88 PROPS_IS_UPDATED
99} from '../../../constants.js' ;
1010import { legacy_mode_flag } from '../../flags/index.js' ;
11- import { get_descriptor , is_function } from '../../shared/utils.js' ;
11+ import {
12+ define_property ,
13+ get_descriptor ,
14+ get_descriptors ,
15+ is_function
16+ } from '../../shared/utils.js' ;
1217import { LEGACY_DERIVED_PROP , LEGACY_PROPS , STATE_SYMBOL } from '../constants.js' ;
1318import * as e from '../errors.js' ;
1419import { proxy } from '../proxy.js' ;
1520import { captured_signals , get , is_flushing_effect , untrack } from '../runtime.js' ;
1621import { derived , derived_safe_equal } from './deriveds.js' ;
17- import { teardown } from './effects.js' ;
22+ import { render_effect , teardown } from './effects.js' ;
1823import { safe_equals } from './equality.js' ;
1924import { inspect_effects , mutable_source , set , source , update } from './sources.js' ;
2025import { capture_store_binding } from './store.js' ;
@@ -406,39 +411,39 @@ export function prop(props, key, flags, fallback) {
406411
407412/**
408413 *
409- * @param {Record<string| symbol, unknown> } props
414+ * @param {Record<string | symbol, unknown> } props
410415 */
411416export function safe_props ( props ) {
412417 let unmounting = false ;
413418 teardown ( ( ) => {
414419 unmounting = true ;
415420 } ) ;
416- const deriveds = new Map ( ) ;
417- return untrack ( ( ) => {
418- /**
419- * @type {Map<string|symbol, unknown> }
420- */
421- const olds = new Map ( Object . entries ( props ) ) ;
422-
423- return new Proxy (
424- { } ,
425- {
426- get ( _ , key ) {
427- if ( ! deriveds . has ( key ) ) {
428- deriveds . set (
429- key ,
430- derived ( ( ) => {
431- if ( unmounting ) {
432- return olds . get ( key ) ;
433- }
434- olds . set ( key , props [ key ] ) ;
435- return props [ key ] ;
436- } )
437- ) ;
438- }
439- return get ( deriveds . get ( key ) ) ;
421+
422+ /** @type {typeof props } */
423+ var values = { } ;
424+
425+ for ( const key in props ) {
426+ const descriptor = /** @type {PropertyDescriptor } */ ( get_descriptor ( props , key ) ) ;
427+
428+ if ( descriptor . get ) {
429+ let latest = props [ key ] ;
430+
431+ render_effect ( ( ) => {
432+ if ( ! unmounting ) {
433+ latest = props [ key ] ;
440434 }
441- }
442- ) ;
443- } ) ;
435+ } ) ;
436+
437+ define_property ( values , key , {
438+ ...descriptor ,
439+ get ( ) {
440+ return unmounting ? latest : props [ key ] ;
441+ }
442+ } ) ;
443+ } else {
444+ values [ key ] = props [ key ] ;
445+ }
446+ }
447+
448+ return values ;
444449}
0 commit comments