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

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

Open
yayxs opened this issue Mar 28, 2024 · 3 comments
Labels
🐞 bug Something isn't working

Comments

@yayxs
Copy link

yayxs commented Mar 28, 2024

版本信息

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
@yayxs yayxs added the 🐞 bug Something isn't working label Mar 28, 2024
@Timeless0911
Copy link
Collaborator

Timeless0911 commented Mar 28, 2024

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
Copy link
Author

yayxs commented Mar 28, 2024

@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
Copy link
Collaborator

Timeless0911 commented Mar 28, 2024

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants