observablehq / feedback

Customer submitted bugs and feature requests
42 stars 3 forks source link

embed duplicates viewof select to show values; different from editor #469

Open aaronkyle opened 2 years ago

aaronkyle commented 2 years ago

Describe the bug When I create a selection input in editor mode, I see only the selection. In the embed mode, the variable is duplicated

To Reproduce Steps to reproduce the behavior: View this as embedded: https://observablehq.com/d/075a638054c366e7 https://observablehq.com/embed/075a638054c366e7

Expected behavior I expect just the input

Screenshots embed-duplicates-viewof-select-element

Desktop (please complete the following information):

mbostock commented 2 years ago

Yeah, the issue here is that the embed code is observing everything in the notebook. If you look at the compiled source of the notebook (https://api.observablehq.com/d/075a638054c366e7.js?v=3) you’ll see that both viewof variable and variable are observable:

export default function define(runtime, observer) {
  const main = runtime.module();
  main.variable(observer()).define(["md"], _1);
  main.variable(observer("viewof variable")).define("viewof variable", ["Inputs"], _variable);
  main.variable(observer("variable")).define("variable", ["Generators", "viewof variable"], (G, _) => G.input(_));
  return main;
}

The embed code will need to have some logic in that says to not observe variable if viewof variable is already observed.

As a workaround, you can select just the cells you want to embed rather than the entire notebook.