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]: Empty text field converts to <br /> #56

Open
monolithed opened this issue Nov 29, 2024 · 2 comments
Open

[bug]: Empty text field converts to <br /> #56

monolithed opened this issue Nov 29, 2024 · 2 comments
Labels
issue: bug Issue reporting a bug

Comments

@monolithed
Copy link

monolithed commented Nov 29, 2024

What version of @strapi/blocks-react-renderer are you using?

lst

What's Wrong?

When the field content is empty, Strapi returns an empty string; however, blocks-react-renderer converts it into a <br>, which breaks the layout.

To Reproduce

I see that this was done intentionally, but I don't understand why.

// Handle empty paragraphs separately as they should render a <br> tag

[
    {
        "type": "paragraph",
        "children": [
            {
                "text": "",
                "bold": false
            }
        ]
    }
]

Expected Behaviour

No br added

There's a similar discussion https://forum.strapi.io/t/richtext-field-returns-br-tag-when-cleared/39507

@monolithed monolithed added the issue: bug Issue reporting a bug label Nov 29, 2024
@mad-zephyr
Copy link

Any updates?

@monolithed
Copy link
Author

Here's a workaround:

const trimBlocksRendererChild = (input: BlocksContent): BlocksContent => {
    return input.filter(({children}) => {
        return children.some((child) => {
            const {text} = child as TextInlineNode;

            return text?.trim() !== '';
        });
    });
};
+ const content = trimBlocksRendererChild(children);

+ <BlocksRenderer content={content} ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug
Projects
None yet
Development

No branches or pull requests

2 participants