Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/src/blocks/Image/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ export const imageRender =
image.alt = block.props.name || "";
image.contentEditable = "false";
image.draggable = false;
if (block.props.previewWidth) {
image.width = block.props.previewWidth;
}
imageWrapper.appendChild(image);

return createResizableFileBlockWrapper(
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/blocks/Video/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export const createVideoBlockSpec = createBlockSpec(
video.controls = true;
video.contentEditable = "false";
video.draggable = false;
video.width = block.props.previewWidth;
if (block.props.previewWidth) {
video.width = block.props.previewWidth;
}
videoWrapper.appendChild(video);

return createResizableFileBlockWrapper(
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/blocks/Image/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const ImagePreview = (
: resolved.downloadUrl
}
alt={alt}
width={props.block.props.previewWidth}
contentEditable={false}
draggable={false}
/>
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/blocks/Video/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const VideoPreview = (
: resolved.downloadUrl
}
controls={true}
width={props.block.props.previewWidth}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Inconsistent handling of zero width compared to core implementation.

The React implementation passes previewWidth directly to the width attribute, which means React will render width="0" when previewWidth is 0. In contrast, the core implementation (lines 95-97 in packages/core/src/blocks/Video/block.ts) uses a truthiness check that prevents setting width when previewWidth is any falsy value, including 0.

While previewWidth=0 is unlikely in practice, the implementations should handle edge cases consistently.

🔧 Align with core's conditional guard pattern

For VideoPreview (line 30):

     <video
       className={"bn-visual-media"}
       src={
         resolved.loadingState === "loading"
           ? props.block.props.url
           : resolved.downloadUrl
       }
       controls={true}
-      width={props.block.props.previewWidth}
+      width={props.block.props.previewWidth || undefined}
       contentEditable={false}
       draggable={false}
     />

For VideoToExternalHTML (line 48):

   const video = props.block.props.showPreview ? (
-    <video src={props.block.props.url} width={props.block.props.previewWidth} />
+    <video src={props.block.props.url} width={props.block.props.previewWidth || undefined} />
   ) : (

This ensures React won't render the width attribute when previewWidth is falsy (including 0), matching the core behavior.

Also applies to: 48-48

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/react/src/blocks/Video/block.tsx` at line 30, The React
implementation passes props.block.props.previewWidth directly into the width
attribute causing width="0" to be emitted; update VideoPreview and
VideoToExternalHTML so they only set the width attribute when
props.block.props.previewWidth is truthy (i.e., use a conditional guard like the
core block does) — locate the uses of props.block.props.previewWidth in the
VideoPreview and VideoToExternalHTML components and change them to only assign
width when that value is truthy.

contentEditable={false}
draggable={false}
/>
Expand All @@ -44,7 +45,7 @@ export const VideoToExternalHTML = (
}

const video = props.block.props.showPreview ? (
<video src={props.block.props.url} />
<video src={props.block.props.url} width={props.block.props.previewWidth} />
) : (
<a href={props.block.props.url}>
{props.block.props.name || props.block.props.url}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Test ServerBlockNoteEditor > converts to HTML (blocksToFullHTML) 1`] = `"<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1"><div class="bn-block-content" data-content-type="heading" data-background-color="blue" data-text-color="yellow" data-text-alignment="right" data-level="2"><h2 class="bn-inline-content"><strong><u>Heading </u></strong><em><s>2</s></em></h2></div><div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="2"><div class="bn-block" data-node-type="blockContainer" data-id="2"><div class="bn-block-content" data-content-type="paragraph" data-background-color="red"><p class="bn-inline-content">Paragraph</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="3"><div class="bn-block" data-node-type="blockContainer" data-id="3"><div class="bn-block-content" data-content-type="bulletListItem"><p class="bn-inline-content">list item</p></div></div></div></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="4"><div class="bn-block" data-node-type="blockContainer" data-id="4"><div class="bn-block-content" data-content-type="image" data-name="Example" data-url="exampleURL" data-caption="Caption" data-preview-width="256" data-file-block=""><figure class="bn-file-block-content-wrapper" style="position: relative; width: 256px;"><div class="bn-visual-media-wrapper"><img class="bn-visual-media" src="exampleURL" alt="Example" draggable="false"><div class="bn-resize-handle" style="left: 4px; display: none;"></div><div class="bn-resize-handle" style="right: 4px; display: none;"></div></div><figcaption class="bn-file-caption">Caption</figcaption></figure></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="5"><div class="bn-block" data-node-type="blockContainer" data-id="5"><div class="bn-block-content" data-content-type="image" data-name="Example" data-url="exampleURL" data-caption="Caption" data-show-preview="false" data-preview-width="256" data-file-block=""><figure class="bn-file-block-content-wrapper" style="position: relative;"><div class="bn-file-name-with-icon"><div class="bn-file-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg></div><p class="bn-file-name">Example</p></div><figcaption class="bn-file-caption">Caption</figcaption></figure></div></div></div></div>"`;
exports[`Test ServerBlockNoteEditor > converts to HTML (blocksToFullHTML) 1`] = `"<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1"><div class="bn-block-content" data-content-type="heading" data-background-color="blue" data-text-color="yellow" data-text-alignment="right" data-level="2"><h2 class="bn-inline-content"><strong><u>Heading </u></strong><em><s>2</s></em></h2></div><div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="2"><div class="bn-block" data-node-type="blockContainer" data-id="2"><div class="bn-block-content" data-content-type="paragraph" data-background-color="red"><p class="bn-inline-content">Paragraph</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="3"><div class="bn-block" data-node-type="blockContainer" data-id="3"><div class="bn-block-content" data-content-type="bulletListItem"><p class="bn-inline-content">list item</p></div></div></div></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="4"><div class="bn-block" data-node-type="blockContainer" data-id="4"><div class="bn-block-content" data-content-type="image" data-name="Example" data-url="exampleURL" data-caption="Caption" data-preview-width="256" data-file-block=""><figure class="bn-file-block-content-wrapper" style="position: relative; width: 256px;"><div class="bn-visual-media-wrapper"><img class="bn-visual-media" src="exampleURL" alt="Example" draggable="false" width="256"><div class="bn-resize-handle" style="left: 4px; display: none;"></div><div class="bn-resize-handle" style="right: 4px; display: none;"></div></div><figcaption class="bn-file-caption">Caption</figcaption></figure></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="5"><div class="bn-block" data-node-type="blockContainer" data-id="5"><div class="bn-block-content" data-content-type="image" data-name="Example" data-url="exampleURL" data-caption="Caption" data-show-preview="false" data-preview-width="256" data-file-block=""><figure class="bn-file-block-content-wrapper" style="position: relative;"><div class="bn-file-name-with-icon"><div class="bn-file-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg></div><p class="bn-file-name">Example</p></div><figcaption class="bn-file-caption">Caption</figcaption></figure></div></div></div></div>"`;

exports[`Test ServerBlockNoteEditor > converts to and from HTML (blocksToHTMLLossy) 1`] = `"<h2 style="background-color: rgb(221, 235, 241); color: rgb(223, 171, 1); text-align: right;" data-background-color="blue" data-text-color="yellow" data-text-alignment="right" data-level="2"><strong><u>Heading </u></strong><em><s>2</s></em></h2><p style="background-color: rgb(251, 228, 228);" data-background-color="red" data-nesting-level="1">Paragraph</p><ul><li data-nesting-level="1"><p class="bn-inline-content">list item</p></li></ul><figure data-name="Example" data-url="exampleURL" data-caption="Caption" data-preview-width="256"><img src="exampleURL" alt="Example" width="256"><figcaption>Caption</figcaption></figure><div data-name="Example" data-url="exampleURL" data-caption="Caption" data-show-preview="false" data-preview-width="256"><a href="exampleURL">Example</a><p>Caption</p></div>"`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
style="position: relative; width: 256px;"
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="example" draggable="false" />
<img
class="bn-visual-media"
src="exampleURL"
alt="example"
draggable="false"
width="256"
/>
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
style="position: relative; width: 256px;"
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="" draggable="false" />
<img
class="bn-visual-media"
src="exampleURL"
alt=""
draggable="false"
width="256"
/>
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
Expand All @@ -37,7 +43,13 @@
style="position: relative; width: 256px;"
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="" draggable="false" />
<img
class="bn-visual-media"
src="exampleURL"
alt=""
draggable="false"
width="256"
/>
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
style="position: relative; width: 256px;"
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="example" draggable="false" />
<img
class="bn-visual-media"
src="exampleURL"
alt="example"
draggable="false"
width="256"
/>
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
style="position: relative; width: 256px;"
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="" draggable="false" />
<img
class="bn-visual-media"
src="exampleURL"
alt=""
draggable="false"
width="256"
/>
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm"
controls=""
draggable="false"
width="0"
></video>
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
src="https://example.com/video.mp4"
controls=""
draggable="false"
width="0"
></video>
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
style="position: relative; width: 256px;"
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="example" draggable="false" />
<img
class="bn-visual-media"
src="exampleURL"
alt="example"
draggable="false"
width="256"
/>
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
style="position: relative; width: 256px;"
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="example" draggable="false" />
<img
class="bn-visual-media"
src="exampleURL"
alt="example"
draggable="false"
width="256"
/>
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
Expand All @@ -39,7 +45,13 @@
style="position: relative; width: 256px;"
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="example" draggable="false" />
<img
class="bn-visual-media"
src="exampleURL"
alt="example"
draggable="false"
width="256"
/>
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
style="position: relative; width: 256px;"
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="example" draggable="false" />
<img
class="bn-visual-media"
src="exampleURL"
alt="example"
draggable="false"
width="256"
/>
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
style="position: relative; width: 256px;"
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="" draggable="false" />
<img
class="bn-visual-media"
src="exampleURL"
alt=""
draggable="false"
width="256"
/>
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
Expand Down
Loading