Repository: excalidraw/excalidraw
File: src/data/restore.ts (TypeScript)

Code before:
  switch (element.type) {
    case "text":
      let fontSize = element.fontSize;
      let fontFamily = element.fontFamily;
      if ("font" in element) {
        const [fontPx, _fontFamily]: [string, string] = (
          element as any
        ).font.split(" ");
        fontSize = parseInt(fontPx, 10);
        fontFamily = getFontFamilyByName(_fontFamily);
      }
      const text = element.text ?? "";

      element = restoreElementWithProperties(element, {
        fontSize,
        fontFamily,
        text,
        textAlign: element.textAlign || DEFAULT_TEXT_ALIGN,
        verticalAlign: element.verticalAlign || DEFAULT_VERTICAL_ALIGN,
        containerId: element.containerId ?? null,
        originalText: element.originalText || element.text,
        // if no lineHeight set, detect it from text height, provided `height`
        // is non-0, otherwise use the default
        lineHeight:
          element.lineHeight ||
          (element.height ? detectLineHeight(element) : DEFAULT_LINE_HEIGHT),
      });

      if (refreshDimensions) {
        element = { ...element, ...refreshTextDimensions(element) };
      }
      return element;
    case "freedraw": {
      return restoreElementWithProperties(element, {
        points: element.points,
        lastCommittedPoint: null,
        simulatePressure: element.simulatePressure,
        pressures: element.pressures,
      });
    }
    case "image":
      return restoreElementWithProperties(element, {
        status: element.status || "pending",
        fileId: element.fileId,
        scale: element.scale || [1, 1],
      });
    case "line":
    // @ts-ignore LEGACY type
    // eslint-disable-next-line no-fallthrough
    case "draw":
    case "arrow": {

Review comment (suggestion):
when height is not defined or 0, we can't detect lineHeight from the element, hence using the default default. This we can leverage when creating text elements programmatically (we just won't supply `height` or `lineHeight`)

Code after:
    case "text":
      let fontSize = element.fontSize;
      let fontFamily = element.fontFamily;
      if ("font" in element) {
        const [fontPx, _fontFamily]: [string, string] = (
          element as any
        ).font.split(" ");
        fontSize = parseFloat(fontPx);
        fontFamily = getFontFamilyByName(_fontFamily);
      }
      const text = element.text ?? "";

      element = restoreElementWithProperties(element, {
        fontSize,
        fontFamily,
        text,
        textAlign: element.textAlign || DEFAULT_TEXT_ALIGN,
        verticalAlign: element.verticalAlign || DEFAULT_VERTICAL_ALIGN,
        containerId: element.containerId ?? null,
        originalText: element.originalText || text,
        // line-height might not be specified either when creating elements
        // programmatically, or when importing old diagrams.
        // For the latter we want to detect the original line height which
        // will likely differ from our per-font fixed line height we now use,
        // to maintain backward compatibility.
        lineHeight:
          element.lineHeight ||
          (element.height
            ? // detect line-height from current element height and font-size
              detectLineHeight(element)
            : // no element height likely means programmatic use, so default
              // to a fixed line height
              getDefaultLineHeight(element.fontFamily)),
      });

      if (refreshDimensions) {
        element = { ...element, ...refreshTextDimensions(element) };
      }
      return element;
    case "freedraw": {
      return restoreElementWithProperties(element, {
        points: element.points,
        lastCommittedPoint: null,
        simulatePressure: element.simulatePressure,
        pressures: element.pressures,
      });
    }
    case "image":
      return restoreElementWithProperties(element, {
        status: element.status || "pending",
        fileId: element.fileId,