Repository: mermaid-js/mermaid
File: packages/mermaid/src/rendering-util/rendering-elements/edges.js (JavaScript)

Code before:
    inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');
    if (!terminalLabels.get(edge.id)) {
      terminalLabels.set(edge.id, {});
    }
    terminalLabels.get(edge.id).startLeft = startEdgeLabelLeft;
    setTerminalWidth(fo, edge.startLabelLeft);
  }
  if (edge.startLabelRight) {
    // Create the actual text element
    const startEdgeLabelRight = elem.insert('g').attr('class', 'edgeTerminals');
    const inner = startEdgeLabelRight.insert('g').attr('class', 'inner');
    const startLabelElement = await createLabel(
      inner,
      edge.startLabelRight,
      getLabelStyles(edge.labelStyle) || '',
      false,
      false
    );
    fo = startLabelElement;
    inner.node().appendChild(startLabelElement);
    let slBox = startLabelElement.getBBox();
    if (useHtmlLabels) {
      const div = startLabelElement.children[0];
      const dv = select(startLabelElement);
      slBox = div.getBoundingClientRect();
      dv.attr('width', slBox.width);
      dv.attr('height', slBox.height);
    }
    inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');

    if (!terminalLabels.get(edge.id)) {
      terminalLabels.set(edge.id, {});
    }
    terminalLabels.get(edge.id).startRight = startEdgeLabelRight;
    setTerminalWidth(fo, edge.startLabelRight);
  }
  if (edge.endLabelLeft) {
    // Create the actual text element
    const endEdgeLabelLeft = elem.insert('g').attr('class', 'edgeTerminals');
    const inner = endEdgeLabelLeft.insert('g').attr('class', 'inner');
    const endLabelElement = await createLabel(
      inner,
      edge.endLabelLeft,
      getLabelStyles(edge.labelStyle) || '',
      false,
      false
    );
    fo = endLabelElement;
    let slBox = endLabelElement.getBBox();
    if (useHtmlLabels) {
      const div = endLabelElement.children[0];

Review comment (refactor):
**suggestion(non-blocking)**:

I think we can remove this `inner.node().appendChild(startLabelElement);`, now that you've changed the above call to https://github.com/mermaid-js/mermaid/blob/f7de94291b708d2965d996e732f79188a5443ab6/packages/mermaid/src/rendering-util/rendering-elements/edges.js#L128-L134

```suggestion
```

But maybe it's better to do this in another PR, since I think this one is already good to merge.

Code after:
      const div = startLabelElement.children[0];
      const dv = select(startLabelElement);
      slBox = div.getBoundingClientRect();
      dv.attr('width', slBox.width);
      dv.attr('height', slBox.height);
    }
    inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');
    if (!terminalLabels.get(edge.id)) {
      terminalLabels.set(edge.id, {});
    }
    terminalLabels.get(edge.id).startLeft = startEdgeLabelLeft;
    setTerminalWidth(fo, edge.startLabelLeft);
  }
  if (edge.startLabelRight) {
    // Create the actual text element
    const startEdgeLabelRight = elem.insert('g').attr('class', 'edgeTerminals');
    const inner = startEdgeLabelRight.insert('g').attr('class', 'inner');
    const startLabelElement = await createLabel(
      inner,
      edge.startLabelRight,
      getLabelStyles(edge.labelStyle) || '',
      false,
      false
    );
    fo = startLabelElement;
    inner.node().appendChild(startLabelElement);
    let slBox = startLabelElement.getBBox();
    if (useHtmlLabels) {
      const div = startLabelElement.children[0];
      const dv = select(startLabelElement);
      slBox = div.getBoundingClientRect();
      dv.attr('width', slBox.width);
      dv.attr('height', slBox.height);
    }
    inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');

    if (!terminalLabels.get(edge.id)) {
      terminalLabels.set(edge.id, {});
    }
    terminalLabels.get(edge.id).startRight = startEdgeLabelRight;
    setTerminalWidth(fo, edge.startLabelRight);
  }
  if (edge.endLabelLeft) {
    // Create the actual text element
    const endEdgeLabelLeft = elem.insert('g').attr('class', 'edgeTerminals');
    const inner = endEdgeLabelLeft.insert('g').attr('class', 'inner');
    const endLabelElement = await createLabel(
      inner,
      edge.endLabelLeft,
      getLabelStyles(edge.labelStyle) || '',
      false,