svelte: Reactivity regression with `5.19.5` with conditional function calls

Describe the bug

I had a bug report in LayerChart that took me a while to track down. It appears between 5.19.4 and 5.19.5 there was a change with reactivity for conditional function calls.

When labelAccessor(data) returns undefined, it will fallback to keyAccessor(data) but if data changes the result is not updated (but valueAccessor(data) and others are).

<slot name="tooltip" {...slotProps}>
  <Tooltip.Root {...props.tooltip?.root} let:data>
    <Tooltip.List {...props.tooltip?.list}>
      <Tooltip.Item
        label={labelAccessor(data) || keyAccessor(data)}
        value={valueAccessor(data)}
        color={cScale?.(c(data))}
        {format}
        {...props.tooltip?.item}
      />
    </Tooltip.List>
  </Tooltip.Root>
</slot>

One workaround is to pull the values up into separate {@const}

<slot name="tooltip" {...slotProps}>
  <Tooltip.Root {...props.tooltip?.root} let:data>
   {@const label = labelAccessor(data)}
   {@const key = keyAccessor(data)}
    <Tooltip.List {...props.tooltip?.list}>
      <Tooltip.Item
        label={label || key}
        value={valueAccessor(data)}
        color={cScale?.(c(data))}
        {format}
        {...props.tooltip?.item}
      />
    </Tooltip.List>
  </Tooltip.Root>
</slot>

But even more surprising is pulling up just the key value (but still use the same fallback) triggers the update.

<slot name="tooltip" {...slotProps}>
  <Tooltip.Root {...props.tooltip?.root} let:data>
   {@const key = keyAccessor(data)}
    <Tooltip.List {...props.tooltip?.list}>
      <Tooltip.Item
        label={labelAccessor(data) || keyAccessor(data)}
        value={valueAccessor(data)}
        color={cScale?.(c(data))}
        {format}
        {...props.tooltip?.item}
      />
    </Tooltip.List>
  </Tooltip.Root>
</slot>

The later is the workaround I added to LayerChart in 0.93.8

Reproduction

Running svelte: '^5.9.5' with layerchart: '0.93.7' and moving between PieChart arcs shows the issue (without the Tooltip unmounting).

See this repo created for the LayerChart issue (thanks @anatoliy-t7). See also the video in the original issue for a demonstration.

Logs


System Info

{
  'svelte': '^5.9.5',
  'layerchart': '0.93.7'
}

Severity

blocking an upgrade

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

@techniq Thanks, mind commenting on the PR stating as much – just so we keep the related context of the bug fix together? Thanks.

Breaking out @const tags will cause them to be read eagerly in DEV, that’s likely why.

I’ll look into the other cases now.

@trueadm will do. Tracking down a minimal repo will take some time as I’m not sure what’s causing it, but I’ll see what I can do

Please just ping me about these issues next time. Also if you could create a minimal repro using our playground rather than using layerchart that would be even more ideal – as we can create a perfect test around it. If not, a new issue is still preferred. 😃