vitepress icon indicating copy to clipboard operation
vitepress copied to clipboard

dup component with <img>+<p> in markdown (SSR)

Open gurgeous opened this issue 3 years ago • 3 comments

Describe the bug

Thanks for creating vitepress, we are loving it!

In markdown w/ SSR, placing a <p> tag directly below an image breaks rendering of the next component. The component is duplicated for some reason. Note that this bug only occurs with SSR (not vitepress dev).

Reproduction

Here is some markdown to try:

![](./someimage.png)
<p>sometext</p>

<MyComponent/>

MyComponent.vue:

<template>
  <div style="width: 10rem; height: 10rem; background: red" />
</template>

On dev it renders as one red box, with SSR it renders as two. The SSR HTML is strange:

<p><img src="..." alt=""></p>
<div style="width: 10rem; height: 10rem; background: red;"></div>
<p></p>
<div style="width:10rem;height:10rem;background:red;"></div>

image

Expected behavior

Component would render properly, or at least identically, in both dev and SSR.

System Info

System:
    OS: macOS 12.4
    CPU: (8) arm64 Apple M1
    Memory: 135.58 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.13.2 - ~/.asdf/installs/nodejs/16.13.2/bin/node
    Yarn: 1.22.18 - ~/.asdf/installs/nodejs/16.13.2/.npm/bin/yarn
    npm: 8.1.2 - ~/.asdf/plugins/nodejs/shims/npm
  Browsers:
    Chrome: 102.0.5005.115
    Firefox: 97.0.1
    Safari: 15.5
  npmPackages:
    vitepress: ^1.0.0-alpha.1 => 1.0.0-alpha.1

Additional context

To workaround the issue, place a newline between the image and the <p> tag, like so:

![](./someimage.png)

<p>sometext</p>

<MyComponent/>

Then everything renders properly.

Validations

  • [X] Follow our Code of Conduct
  • [X] Read the docs.
  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.

gurgeous avatar Jun 10 '22 20:06 gurgeous

Hi! This is actually the commonmark standard. You need to separate markdown and html/vue by at least a blank line. I'm not sure why the content is being duplicated. But giving no space between md and html will generally cause issues with rendering.

brc-dd avatar Jun 10 '22 20:06 brc-dd

I am fine with this. But shouldn't it work the same between dev and SSR? That seems like an issue.

gurgeous avatar Jun 10 '22 20:06 gurgeous

Hmmm, yeah if this doesn't happen in dev, it would surely be hard to catch this... It would be cool if we can have same behaviour in dev too.

kiaking avatar Jun 14 '22 08:06 kiaking

Closing as I can no longer reproduce this in latest (1.0.0-alpha.54)

yyx990803 avatar Mar 13 '23 08:03 yyx990803