Comments (8)
Facing the same issue
"react": "^17.0.2",
"react-dom": "^17.0.2",
"@sanity/block-content-to-react": "^3.0.0",
from block-content-to-react.
Facing the same issue
"react": "^17.0.2", "react-dom": "^17.0.2", "@sanity/block-content-to-react": "^3.0.0",
Exact same setup and issue.
from block-content-to-react.
Okay I figured out what I was doing wrong. Hopefully this helps you @ScholtenSeb and @vonba .
Because the links are annotations, they are actually marks
not types
. When defining my serializer object I had to make the change from
const serializers: Serializers = {
types: {
internalLink: InternalLink,
externalLink: ExternalLink,
}
}
to
const serializers: Serializers = {
marks: {
internalLink: InternalLink,
externalLink: ExternalLink,
}
}
I wrote my own typing for the Serializer object as
interface Serializers {
types?: Record<string, (props: any) => JSX.Element | null>;
marks?: Record<string, (props: any) => JSX.Element | null>;
list?: React.Component;
listItem?: React.Component;
hardBreak?: React.Component;
container?: React.Component;
}
from block-content-to-react.
from block-content-to-react.
@vonba Sorry, I overlooked your original post. Upon a closer look, I don't spot anything different aside from naming differences to what I have.
This is what I have wired. Maybe help spot any difference?
{
type: 'array',
name: 'body',
title: 'Body',
of: [
{
type: 'block',
marks: {
annotations: [
{
name: 'externalLink',
type: 'object',
title: 'External Link',
blockEditor: {
icon: FaExternalLinkAlt,
},
fields: [
{
name: 'url',
type: 'url'
}
]
},
const ExternalLink: FC<{mark: any}> = ({mark, children}) => {
const { url} = mark;
return (
<a href={url} className="link external-link">{children}</a>
)
}
const serializers: Serializers = {
marks: {
externalLink: ExternalLink,
}
}
export const BlockContent: FC<BlockContentProps> = ({blocks, className}) => {
return <SanityBlockContent blocks={blocks}
className={classnames('sanity-block-content', className)}
serializers={serializers}
ignoreUnknownTypes={false}
renderContainerOnSingleChild={true}
/>
};
from block-content-to-react.
They really look identical to me except that you are setting the icon in the editor, and that I'm adding the "new tab" option.
The thing that's crazy about it is that when the block data reaches the front end the custom elements are just named as random IDs. So must have something to do with how the stored data is interpreted.
from block-content-to-react.
It actually seems like this is how the contents comes out through the raw GraphQL query.
The block below should be a link, but it's missing the url property and the mark should be "link" instead of "b4ff1a687243".
{
"_key": "01617238a47b",
"_type": "span",
"marks": [
"b4ff1a687243"
],
"text": "Magdalena Wosinka"
},
However, the content above is still read back correctly to the editor, so the information isn't lost.
from block-content-to-react.
I found the issue.
A while back I found a bug where in some cases the markDefs
field was missing from blocks.
My solution was to add an empty markDefs
field on all blocks.
By doing that I am overwriting any custom marks. I didn't notice it at the time because I wasn't using any custom annotations.
Not sure if the bug I mention is still an issue in newer versions of Sanity.
from block-content-to-react.
Related Issues (20)
- Feature request: Override react-native styles HOT 2
- Classname not passed when only single child
- Issue with Ordered Lists HOT 2
- Empty alt not added to images in default serializer HOT 1
- Output wrapped in an empty div container HOT 1
- missing markDefs on `gatsby-source-sanity` graphql API breaks BlockContent? HOT 8
- "Unknown block type 'text'" error when rendering text from block content field HOT 2
- BlockContent component tries to render a link using the key property as the mark name HOT 1
- Blocks that has _type different from "block" doesn't get correct list processing HOT 2
- Can't create list in sanity HOT 2
- Images do not render when using block serializers HOT 4
- Pass projectId and dataset to the block renderer (only after using my own extended serializer) HOT 2
- How to render empty <p></p> as linebreak? HOT 4
- Apply truncate function on content HOT 1
- How can i use Katex? HOT 2
- Invalid Hook Call when deploying Sanity HOT 1
- BlockContent displays only plain text HOT 1
- Pass in additional props to serialisers from render level HOT 1
- Link urls being re-used HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from block-content-to-react.