Checklist-Tools-Website icon indicating copy to clipboard operation
Checklist-Tools-Website copied to clipboard

Fix bug where >2 links causes duplicates on page re-rendering

Open xenithorb opened this issue 5 years ago • 2 comments

  • Prior to this fix, any task object that had greater-than 2 links would duplicate n-1 of those links every time the page rendered. I made an assumption that it had something to do with Preact duplicating based on passing the entire link object to key= and it seems to work simply by removing the key= attribute altogether.
  • Also removed the unused i parameter

xenithorb avatar May 09 '19 20:05 xenithorb

Full disclosure: I have really no actual idea why it was duplicating links in the first place and merely got lucky with this patch. I'm not a JS developer and don't understand the code very well to really understand what was happening at the Preact level for it to duplicate link items.

I do know that the data object in localStorage was fine, so it seems to be a rendering issue only.

xenithorb avatar May 09 '19 20:05 xenithorb

You should be able to replicate with this JSON:

{
    "group_categories": [
        {
            "title_group": "Heading", 
            "categories": [
                {
                    "tasks": [
                        {
                            "explications": "This area will start to duplicate links after a re-render", 
                            "links": [
                                {
                                    "text": "Google", 
                                    "type": "tools", 
                                    "path": "https://google.com"
                                }, 
                                {
                                    "text": "Github", 
                                    "type": "link", 
                                    "path": "https://github.com"
                                }, 
                                {
                                    "text": "Gitlab", 
                                    "type": "link", 
                                    "path": "https://gitlab.com"
                                }
                            ], 
                            "title": "Duplicate links after >2"
                        }
                    ], 
                    "title": "Task title"
                }
            ]
        }
    ], 
    "name": "Test checklist for duplicate links"
}

xenithorb avatar May 09 '19 20:05 xenithorb