Embedded cell showing as undefined

My notebook (Doppler Laser Cooling / ccesare | Observable) has a cell named “graphic” that works well, but when I try to export via Export → Embed Cells, I see “graphic = undefined” as soon as I click the preview. (I’ve forked this from another notebook for ease of sharing and making changes.)

This embed used to work (I’ve had it embedded for ages here: The Quantum Atlas | Laser Cooling), but I’ve just noticed the “graphic = undefined” error.

Given that it used to work, I was thinking this must be due to a change in how Observable provides these embeds. But maybe I just was lucky before and there is actually something wrong with the notebook? That wouldn’t explain why it works fine in the notebook itself but fails when embedded.

Any ideas?

1 Like

Note that your variable mutable paused starts off as true, and that’s the value that it probably has when graphic is loaded. Somewhere along the line, mutable pause is set to false and, since your yield is statement is inside a while(!pased) loop, the result is undefined. The quick fix is to embed paused as well.

If I were embedding this via the Javascript runtime, I’d simply use CSS to hide the div containing mutable paused.

I can’t verify that this “used to work” but there certainly can be some variability when you’ve got this kind of well hidden side effect, so I can believe that it might have.

1 Like

Hi @ccesare!

A mix of both? :sweat_smile:

We published a major update to embeds at the end of last year. One of the less advertised changes was that we are now more explicit about which cells to run in an embed. What that means in detail:

  • In the old version, all cells would run (“compute”) in the background, regardless of whether they were actually selected or were dependencies (“upstream cells”) of selected cells.
  • In the new version, in addition to the selected cells we only compute cells that depend on any of the selected cells (“downstream cells”), directly or indirectly. Doing so lets us account for most side effects that other cells may produce.

@mcmcclur helpfully pointed out that in your case one of the side effects involves a mutable. I would have expected that to work, and will need take a closer look to figure out if we need to make changes to our detection of downstream cells.

Your notebook uses a side effect in another side effect, so I’m afraid we can’t detect that dependency. However, including the pause button (viewof pause) should suffice to make your embed work again.

Thank you @mootari and @mcmcclur! Including the button does seem to do the trick!