question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

{#key} not working inside {#each}/{#if}

See original GitHub issue

Describe the bug

{#key} and its body that work doesn’t work inside {#each} block.

I want to display the duration passed every second by calculation instead of assigning a value to an object in an array and triggering update with assignment.

Reproduction

https://svelte.dev/repl/d4112f1ae05046bdb48be42b62cc4c8d?version=3.42.4

Logs

No response

System Info

System:
    OS: Windows 10 10.0.18363
    CPU: (8) x64 Intel(R) Core(TM) i7-3610QM CPU @ 2.30GHz
    Memory: 6.11 GB / 11.90 GB
  Binaries:
    Node: 14.16.0 - D:\Program Files\nodejs\node.EXE
    npm: 6.14.11 - D:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 91.0.4472.164
    Edge: Spartan (44.18362.1533.0)
    Internet Explorer: 11.0.18362.1
  npmPackages:
    svelte: ^3.38.2 => 3.38.2

Severity

annoyance

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dummdidummcommented, Apr 29, 2022

It was, thanks for noticing!

1reaction
Prinzhorncommented, Aug 28, 2021

This does work in contrast (I simply output the key {force_update_heartbeat}): https://svelte.dev/repl/d2358d0e2e9c4052afad3ec85140802b?version=3.42.4 So it seems like Svelte does not add the key to the observed properties when inside each. But if it is there anyway the update works.

Edit: even with the bug fixed your REPL doesn’t look Svelte-like to me. You are basically imperatively controlling the reactivity by setting force_update_heartbeat just to call foo(). If you can show a more real world example I’m sure there is a better way. Why not update the array items directly each tick? https://svelte.dev/repl/dc3ac91d693a466693a1935a96d06c73?version=3.42.4

Read more comments on GitHub >

github_iconTop Results From Across the Web

Some of the Keys on My Computer Keyboard Aren't Working.
When the keys on a keyboard don't work, it's usually due to mechanical failure. If this is the case, the keyboard needs to...
Read more >
A key isn't working on my keyboard and it's not the keyboard
Try this: -Plug your keyboard into another port. -Open Start and search Device Manager. -Expand the "Keyboards" section.
Read more >
Find the last element of an array while using a foreach loop in ...
It sounds like you want something like this: $numItems = count($arr); $i = 0; foreach($arr as $key=>$value) { if(++$i === $numItems) { echo...
Read more >
Windows Key Not Working in Windows 10? 10+ Ways to Fix It
Fortunately, there are troubleshooting steps you can take to resolve the Windows key not working problem for good.
Read more >
Query editor replacing values based on another column
Solved: I can't seem to get this to work in query editor: let Source = Excel. ... ReplaceValue(#"Replaced OTH",each if [Surname] = "Manly"...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found