Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue3 Warn. default slot #209

Open
gyxoBka opened this issue Nov 19, 2023 · 1 comment
Open

Vue3 Warn. default slot #209

gyxoBka opened this issue Nov 19, 2023 · 1 comment
Assignees
Labels
P2 Normal issue

Comments

@gyxoBka
Copy link

gyxoBka commented Nov 19, 2023

[Vue warn]: Non-function value encountered for default slot. Prefer function slots for better performance.

Reproduction: link

@JiLiZART JiLiZART self-assigned this Nov 19, 2023
@JiLiZART JiLiZART added the P2 Normal issue label Nov 19, 2023
@gyxoBka
Copy link
Author

gyxoBka commented Nov 19, 2023

@JiLiZART fix default slot warn and node mismatch warn

function tagToVueNode(createElement, node, index) {
  const { class: className, style, ...domProps } = node.attrs || {};

  return createElement(
    node.tag,
    {
      key: index,
      class: className,
      style,
      ...domProps,
    },
    {
      default: () => isContentEmpty(node.content) ? null : renderToVueNodes(createElement, node.content),
    },
  );
}

function renderToVueNodes(createElement, nodes) {
  return [].concat(nodes).reduce((arr, node, index) => {
    if (isTagNode(node)) {
      arr.push(tagToVueNode(createElement, node, index));
    } else if (isStringNode(node)) {
      if (arr[arr.length - 1] && isStringNode(arr[arr.length - 1])) {
        arr[arr.length - 1] += node
      } else {
        arr.push(node);
      }
    }

    return arr;
  }, []);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Normal issue
Projects
None yet
Development

No branches or pull requests

2 participants