In our project we have a structuredtext field that has a inline record link to an other model.
When querying the graphql server this is the response that i got:
"mainDescription": {
"value": {
"schema": "dast",
"document": {
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "span",
"value": "Hello"
}
]
},
{
"type": "paragraph",
"children": [
{
"item": "175921359",
"type": "inlineItem"
}
]
}
]
}
},
"links": [
{
"__typename": "NotificationRecord",
"id": "175921359",
"statusType": "warning",
"description": {
"value": {
"schema": "dast",
"document": {
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "span",
"value": "This is a warning message"
}
]
}
]
}
}
}
}
],
"blocks": []
},
In my NextJS AppRouter server component I have this code to render the structedtext with help of the StructuredText component of react-datocms:
import { NotificationFragment } from "@/lib/client";
import type { StructuredTextGraphQlResponse } from "react-datocms";
import { StructuredText } from "react-datocms/structured-text";
import { Message, MessageType } from "ui";
type DatoStructuredTextProps = {
data: StructuredTextGraphQlResponse;
};
export const DatoStructuredText = ({ data }: DatoStructuredTextProps) => {
return (
<StructuredText
data={data}
renderBlock={() => <></>}
renderInlineRecord={({ record }) => {
switch (record.__typename) {
case "NotificationRecord":
const parsed = record as NotificationFragment;
return (
<Message
message={
<DatoStructuredText
data={parsed.description}
/>
}
type={record.statusType as MessageType}
showIcon={false}
/>
);
default:
return null;
}
}}
/>
);
};
This is my Message component:
export const Message = ({
message,
showIcon = true,
type = "info",
iconSize = "lg",
}: MessageProps) => {
const { base } = styles({ type });
return (
<div className={base()}>
{showIcon && (
<FontAwesomeIcon icon={typeToIconMap[type]} size={iconSize} />
)}
{message}
</div>
);
};
The StructuredText component wraps the message component in a
tag, then renders a div tag and inside that a
tag again since we use the StructuredText component again to render the message.
To my HTML looks like this:
<p>
<div>
<p>NEW - required by law</p>
</div>
</p>
I found this already:
So my question is how can I overcome this issue with the StructedText render? I basicly want to skip some <p>
tags if it is just for inline record or blocks
Kind regards,
Kasper