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: textnode with content "null" is rendered as "null" not whitespace #5229

Closed
2 tasks done
joukhar opened this issue Jul 10, 2023 · 6 comments
Closed
2 tasks done

Comments

@joukhar
Copy link

joukhar commented Jul 10, 2023

GrapesJS version

  • I confirm to use the latest version of GrapesJS

What browser are you using?

Chrome Version 114.0.5735.199 (Official Build) (64-bit)

Reproducible demo link

N/A

Describe the bug

How to reproduce the bug?

  1. Drop this component
    <div class=\"flex items-center rounded shadow-md overflow-hidden max-w-xl relative dark:bg-gray-900 dark:text-gray-100\"> <div class=\"self-stretch flex items-center px-3 flex-shrink-0 dark:bg-gray-700 dark:text-violet-400\"> <svg xmlns=\"http://www.w3.org/2000/svg\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" class=\"h-8 w-8\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z\"></path></svg> </div><div class=\"p-4 flex-1\"> <h3 class=\"text-xl font-bold\">Error</h3> <p class=\"text-sm dark:text-gray-400\">The password is incorrect. Do you need to <a href=\"#\" rel=\"referrer noopener\" class=\"underline\">recover your password?</a> </p></div><button type=\"button\" class=\"absolute top-2 right-2\"> <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\" fill=\"currentColor\" class=\"h-4 w-4 p-2 rounded cursor-pointer\"><path fill-rule=\"evenodd\" d=\"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z\" clip-rule=\"evenodd\"></path></svg> </button> </div>
  2. save it and load the page
  3. and page object should look something like this
  4. if you load components object instead of pageManager you will get the same result
 "pages": [
        {
            "id": "rQIn3fqFFfC1xkZ5",
            "frames": [
                {
                    "component": {
                        "type": "wrapper",
                        "stylable": [
                            "background",
                            "background-color",
                            "background-image",
                            "background-repeat",
                            "background-attachment",
                            "background-position",
                            "background-size"
                        ],
                        "components": [
                            {
                                "classes": [
                                    "flex",
                                    "items-center",
                                    "rounded",
                                    "shadow-md",
                                    "overflow-hidden",
                                    "max-w-xl",
                                    "relative",
                                    "dark:bg-gray-900",
                                    "dark:text-gray-100"
                                ],
                                "components": [
                                    {
                                        "type": "textnode",
                                        "content": null
                                    },
                                    {
                                        "classes": [
                                            "self-stretch",
                                            "flex",
                                            "items-center",
                                            "px-3",
                                            "flex-shrink-0",
                                            "dark:bg-gray-700",
                                            "dark:text-violet-400"
                                        ],
                                        "components": [
                                            {
                                                "type": "textnode",
                                                "content": null
                                            },
                                            {
                                                "type": "svg",
                                                "classes": [
                                                    "h-8",
                                                    "w-8"
                                                ],
                                                "resizable": {
                                                    "ratioDefault": true
                                                },
                                                "attributes": {
                                                    "fill": "none",
                                                    "xmlns": "http://www.w3.org/2000/svg",
                                                    "stroke": "currentColor",
                                                    "viewBox": "0 0 24 24"
                                                },
                                                "components": [
                                                    {
                                                        "type": "svg-in",
                                                        "tagName": "path",
                                                        "resizable": {
                                                            "ratioDefault": true
                                                        },
                                                        "attributes": {
                                                            "d": "M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z",
                                                            "stroke-width": "2",
                                                            "stroke-linecap": "round",
                                                            "stroke-linejoin": "round"
                                                        }
                                                    }
                                                ]
                                            },
                                            {
                                                "type": "textnode",
                                                "content": null
                                            }
                                        ]
                                    },
                                    {
                                        "type": "text",
                                        "classes": [
                                            "p-4",
                                            "flex-1"
                                        ],
                                        "components": [
                                            {
                                                "type": "textnode",
                                                "content": null
                                            },
                                            {
                                                "type": "text",
                                                "classes": [
                                                    "text-xl",
                                                    "font-bold"
                                                ],
                                                "tagName": "h3",
                                                "components": [
                                                    {
                                                        "type": "textnode",
                                                        "content": "Error"
                                                    }
                                                ]
                                            },
                                            {
                                                "type": "textnode",
                                                "content": null
                                            },
                                            {
                                                "type": "text",
                                                "classes": [
                                                    "text-sm",
                                                    "dark:text-gray-400"
                                                ],
                                                "tagName": "p",
                                                "components": [
                                                    {
                                                        "type": "textnode",
                                                        "content": "The password is incorrect. Do you need to"
                                                    },
                                                    {
                                                        "type": "link",
                                                        "classes": [
                                                            "underline"
                                                        ],
                                                        "attributes": {
                                                            "rel": "referrer noopener",
                                                            "href": "#"
                                                        },
                                                        "components": [
                                                            {
                                                                "type": "textnode",
                                                                "content": "recover your password?"
                                                            }
                                                        ]
                                                    },
                                                    {
                                                        "type": "textnode",
                                                        "content": null
                                                    }
                                                ]
                                            }
                                        ]
                                    },
                                    {
                                        "type": "button",
                                        "classes": [
                                            "absolute",
                                            "top-2",
                                            "right-2"
                                        ],
                                        "attributes": {
                                            "type": "button"
                                        },
                                        "components": [
                                            {
                                                "type": "textnode",
                                                "content": null
                                            },
                                            {
                                                "type": "svg",
                                                "classes": [
                                                    "h-4",
                                                    "w-4",
                                                    "p-2",
                                                    "rounded",
                                                    "cursor-pointer"
                                                ],
                                                "resizable": {
                                                    "ratioDefault": true
                                                },
                                                "attributes": {
                                                    "fill": "currentColor",
                                                    "xmlns": "http://www.w3.org/2000/svg",
                                                    "viewBox": "0 0 20 20"
                                                },
                                                "components": [
                                                    {
                                                        "type": "svg-in",
                                                        "tagName": "path",
                                                        "resizable": {
                                                            "ratioDefault": true
                                                        },
                                                        "attributes": {
                                                            "d": "M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",
                                                            "clip-rule": "evenodd",
                                                            "fill-rule": "evenodd"
                                                        }
                                                    }
                                                ]
                                            },
                                            {
                                                "type": "textnode",
                                                "content": null
                                            }
                                        ]
                                    },
                                    {
                                        "type": "textnode",
                                        "content": null
                                    }
                                ]
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "styles": [],
    "components": [
        {
            "classes": [
                "flex",
                "items-center",
                "rounded",
                "shadow-md",
                "overflow-hidden",
                "max-w-xl",
                "relative",
                "dark:bg-gray-900",
                "dark:text-gray-100"
            ],
            "components": [
                {
                    "type": "textnode",
                    "content": null
                },
                {
                    "classes": [
                        "self-stretch",
                        "flex",
                        "items-center",
                        "px-3",
                        "flex-shrink-0",
                        "dark:bg-gray-700",
                        "dark:text-violet-400"
                    ],
                    "components": [
                        {
                            "type": "textnode",
                            "content": null
                        },
                        {
                            "type": "svg",
                            "classes": [
                                "h-8",
                                "w-8"
                            ],
                            "resizable": {
                                "ratioDefault": true
                            },
                            "attributes": {
                                "fill": "none",
                                "xmlns": "http://www.w3.org/2000/svg",
                                "stroke": "currentColor",
                                "viewBox": "0 0 24 24"
                            },
                            "components": [
                                {
                                    "type": "svg-in",
                                    "tagName": "path",
                                    "resizable": {
                                        "ratioDefault": true
                                    },
                                    "attributes": {
                                        "d": "M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z",
                                        "stroke-width": "2",
                                        "stroke-linecap": "round",
                                        "stroke-linejoin": "round"
                                    }
                                }
                            ]
                        },
                        {
                            "type": "textnode",
                            "content": null
                        }
                    ]
                },
                {
                    "type": "text",
                    "classes": [
                        "p-4",
                        "flex-1"
                    ],
                    "components": [
                        {
                            "type": "textnode",
                            "content": null
                        },
                        {
                            "type": "text",
                            "classes": [
                                "text-xl",
                                "font-bold"
                            ],
                            "tagName": "h3",
                            "components": [
                                {
                                    "type": "textnode",
                                    "content": "Error"
                                }
                            ]
                        },
                        {
                            "type": "textnode",
                            "content": null
                        },
                        {
                            "type": "text",
                            "classes": [
                                "text-sm",
                                "dark:text-gray-400"
                            ],
                            "tagName": "p",
                            "components": [
                                {
                                    "type": "textnode",
                                    "content": "The password is incorrect. Do you need to"
                                },
                                {
                                    "type": "link",
                                    "classes": [
                                        "underline"
                                    ],
                                    "attributes": {
                                        "rel": "referrer noopener",
                                        "href": "#"
                                    },
                                    "components": [
                                        {
                                            "type": "textnode",
                                            "content": "recover your password?"
                                        }
                                    ]
                                },
                                {
                                    "type": "textnode",
                                    "content": null
                                }
                            ]
                        }
                    ]
                },
                {
                    "type": "button",
                    "classes": [
                        "absolute",
                        "top-2",
                        "right-2"
                    ],
                    "attributes": {
                        "type": "button"
                    },
                    "components": [
                        {
                            "type": "textnode",
                            "content": null
                        },
                        {
                            "type": "svg",
                            "classes": [
                                "h-4",
                                "w-4",
                                "p-2",
                                "rounded",
                                "cursor-pointer"
                            ],
                            "resizable": {
                                "ratioDefault": true
                            },
                            "attributes": {
                                "fill": "currentColor",
                                "xmlns": "http://www.w3.org/2000/svg",
                                "viewBox": "0 0 20 20"
                            },
                            "components": [
                                {
                                    "type": "svg-in",
                                    "tagName": "path",
                                    "resizable": {
                                        "ratioDefault": true
                                    },
                                    "attributes": {
                                        "d": "M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",
                                        "clip-rule": "evenodd",
                                        "fill-rule": "evenodd"
                                    }
                                }
                            ]
                        },
                        {
                            "type": "textnode",
                            "content": null
                        }
                    ]
                },
                {
                    "type": "textnode",
                    "content": null
                }
            ]
        }
    ]

What is the expected behavior?
after saving and loading pages object, it convert whitespace to "null" and it shows "null" instead of whitespace.

What is the current behavior?

And to see nulls on the page u should export page using grapesj-export plugin .
and exported page will look like this :
Screenshot 2023-07-10 114242

in brief, this is what cause the issue :
{ "type": "textnode", "content": null },

this issue appeared only in the latest versions grapesjs>v0.18.4

Note
This issue is not from my server or even source code of the component itself

Code of Conduct

  • I agree to follow this project's Code of Conduct
@artf
Copy link
Member

artf commented Jul 11, 2023

Hi @joukhar is it happening with the latest version?

I'm able to see nulls in the export code if I use your exact JSON example (that should be fixable), but I'm unable to generate those textnodes with nulls by using your HTML example, can you create a reproducible demo for that use case?

Not sure in which case the textnode might be null but for sure we can prevent that...

@joukhar
Copy link
Author

joukhar commented Jul 11, 2023

thanks for the replay, if you need demo so please give me some time until i make one , i will comment again when im finished it
the problem happens only when u store it and load it, but when u drop the component for the first time nothing happened

@joukhar
Copy link
Author

joukhar commented Jul 11, 2023

Here is The demo
https://codesandbox.io/s/joukhar-testing-njwvnm?file=/index.html

You can see the result after storing and loading the original component

My suggestion is:

to replace null with whitespace
{ "type": "textnode", "content": null }, to { "type": "textnode", "content": ' ' },
or detect when content is null and render whitespace instead

Note:

  • there is original component source: when u drop it nothing happened
  • I used components object instead of pages object, because components object is where the issue, specially
    { "type": "textnode", "content": null },
  • and u can see nulls, when export the page or even in the source code

Screenshot 2023-07-11 111745

Screenshot 2023-07-11 111826

@artf artf closed this as completed in afc680f Jul 11, 2023
@artf
Copy link
Member

artf commented Jul 11, 2023

@joukhar so I guess you can confirm that right now it's not possible to generate the textnode with null unless is passed explicitly in the json

@joukhar
Copy link
Author

joukhar commented Jul 17, 2023

one last question
When will you release a new version?

i can't build it locally, it shows many errors and i don't have enough time for them
i will wait until u release new version

@artf
Copy link
Member

artf commented Jul 17, 2023

Probably in the first week of August

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants