web-infra-dev / rspress

🦀💨 A fast Rspack-based static site generator.
https://rspress.dev
MIT License
1.41k stars 130 forks source link

[Bug]: Warning: validateDOMNesting(...): <a> cannot appear as a descendant of <a>. #875

Open yayxs opened 7 months ago

yayxs commented 7 months ago

版本信息

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
    Memory: 2.38 GB / 15.76 GB
  Browsers:
    Edge: Chromium (122.0.2365.92)
    Internet Explorer: 11.0.19041.3636

Other Info:

 "devDependencies": {
    "rspress": "^1.16.1",
    "ts-node": "^10.9.2",
    "typescript": "^5.4.3"
  },
  "dependencies": {
    "@codesandbox/sandpack-react": "^2.13.7"
  }

问题详情

mdx 文件中,a 标签的渲染似乎出现了嵌套问题 我的mdx内容如下:

# ArrayBuffer

- [https://zh.javascript.info/arraybuffer-binary-arrays](https://zh.javascript.info/arraybuffer-binary-arrays)

image

can see:

看起来是这段代码: packages/theme-default/src/components/Link/index.tsx

if (!isExternal) {
    return (
      <a
        {...rest}
        className={`${styles.link} ${className} cursor-pointer`}
        rel={rel}
        target={target}
        onClick={handleNavigate}
        href={withBaseUrl}
      >
        {children}
      </a>
    );
  }

  return (
    <a
      {...rest}
      href={withBaseUrl}
      target={target}
      rel={rel}
      className={`${styles.link} ${className}`}
    >
      {children}
    </a>
  );

复现链接

https://github.com/yayxs/computer-organization-learn/blob/main/docs/arraybuffer/start/introduction.mdx

复现步骤

pnpm run dev
Timeless0911 commented 7 months ago

maybe you should use another name in [https://zh.javascript.info/arraybuffer-binary-arrays], do not use a link in []

e.g. arraybuffer-binary-arrays

yayxs commented 7 months ago

@Timeless0911 是的,我也有注意到。 当我在mdx中写入这样的内容:

# ArrayBuffer

- [not link](https://zh.javascript.info/arraybuffer-binary-arrays)

渲染出来的 a 就是没有嵌套的,请问这个是个bug吗?页面中链接显示的文本有的时候需要是链接


Yes, I noticed that too. When I write something like this in mdx:

#ArrayBuffer

- [not link](https://zh.javascript.info/arraybuffer-binary-arrays)

The rendered a is not nested. Is this a bug? The text displayed as a link on the page sometimes needs to be a link

Timeless0911 commented 7 months ago

If there is a link in [], the logic of the code you posted seems to be entered twice, because the children variable rendered is still a Link. This should be an issue with mdx-rs parsing, can you help take a look? @sanyuan0704

After mdx-rs compile:

 <p>
   <a href="https://example.com" target="_blank" rel="noopener noreferrer"
     ><a href="https://example.com" target="_blank" rel="noopener noreferrer"
       >https://example.com</a
     ></a
   >
 </p>