Title: List View null ref on cell reuse · Issue #10000 · NativeScript/NativeScript · GitHub
Open Graph Title: List View null ref on cell reuse · Issue #10000 · NativeScript/NativeScript
X Title: List View null ref on cell reuse · Issue #10000 · NativeScript/NativeScript
Description: Issue Description When adding multiple items to a list view at runtime, on iOS only, we get a crash: Nativescript encountered a fatal error: Uncaught TypeError: cannot read property 'removeFromSuperview' of null at _prepareCell(file: ......
Open Graph Description: Issue Description When adding multiple items to a list view at runtime, on iOS only, we get a crash: Nativescript encountered a fatal error: Uncaught TypeError: cannot read property 'removeFromSupe...
X Description: Issue Description When adding multiple items to a list view at runtime, on iOS only, we get a crash: Nativescript encountered a fatal error: Uncaught TypeError: cannot read property 'removeFrom...
Opengraph URL: https://github.com/NativeScript/NativeScript/issues/10000
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"List View null ref on cell reuse","articleBody":"### Issue Description\n\nWhen adding multiple items to a list view at runtime, on iOS only, we get a crash:\r\n```\r\nNativescript encountered a fatal error: Uncaught TypeError: cannot read property 'removeFromSuperview' of null at _prepareCell(file: ...core/ui/list-view/index.ios.js\r\n```\r\n\r\nInvestigating further it was determined that the culprit is the code in `list-view/index.ios.ts::_prepareCell()`:\r\n\r\n```ts\r\n this._removeContainer(cell);\r\n (\u003cUIView\u003ecell.view.nativeViewProtected).removeFromSuperview(); \r\n```\r\n\r\nThe remove container method makes a call to\r\n\r\n```ts\r\n view.parent._removeView(view);\r\n```\r\nwhich sets the cell's `nativeViewProtected` to null as part of the parent's tear down, causing the removeFromSuperview() call to fail.\r\n\r\nThe easy workaround/fix is to make the remove call null safe eg \r\n\r\n```ts\r\n(\u003cUIView\u003e cell.view?.nativeViewProtected)?.removeFromSuperview()\r\n```\r\n\r\n\n\n### Reproduction\n\nhttps://stackblitz.com/edit/nativescript-stackblitz-templates-xtpbxb?file=app/components/Home.svelte\r\n\r\nor inline\r\n\r\n```svelte\r\n\u003cpage\u003e\r\n \u003cactionBar title=\"My Tasks\" /\u003e\r\n \u003ctabView\u003e\r\n \u003ctabViewItem title=\"To Do\"\u003e\r\n \u003cgridLayout columns=\"*,120\" rows=\"70,*\"\u003e\r\n \u003c!-- Configures the text field and ensures that pressing Return on the keyboard\r\n produces the same result as tapping the button. --\u003e\r\n \u003ctextField col=\"0\" row=\"0\" bind:text=\"{textFieldValue}\" hint=\"Type new task...\" editable=\"true\"\r\n on:returnPress=\"{onButtonTap}\" /\u003e\r\n \u003cbutton col=\"1\" row=\"0\" text=\"Add task\" on:tap=\"{onButtonTap}\" /\u003e\r\n\r\n \u003clistView items=\"{todos}\" on:itemTap=\"{onItemTap}\" row=\"1\" colSpan=\"2\"\u003e\r\n \u003cTemplate let:item\u003e\r\n \u003clabel text=\"{item.name}\" textWrap=\"true\" /\u003e\r\n \u003c/Template\u003e\r\n \u003c/listView\u003e\r\n \u003c/gridLayout\u003e\r\n \u003c/tabViewItem\u003e\r\n \u003ctabViewItem title=\"Completed\"\u003e\r\n \u003clabel textWrap=\"true\"\u003eThis tab will list completed tasks for tracking.\u003c/label\u003e\r\n \u003c/tabViewItem\u003e\r\n \u003c/tabView\u003e\r\n\u003c/page\u003e\r\n\r\n\u003cscript\u003e\r\n\t\timport { Template } from 'svelte-native/components'\r\n\r\n\t\tlet todos = []\r\n\t\tlet textFieldValue = \"\"\r\n\r\n\t\tfunction onItemTap(args) {\r\n\t\t\t\tconsole.log(`Item ${todos[args.index].name} at index: ${args.index} was tapped`);\r\n\t\t}\r\n\r\n\t\tfunction onButtonTap() {\r\n\t\t\tif (textFieldValue === \"\") return; // Prevents users from entering an empty string.\r\n\t\t\tconsole.log(\"New task added: \" + textFieldValue + \".\"); // Logs the newly added task in the console for debugging.\r\n\t\t\ttodos = [{ name: textFieldValue }, ...todos] // Adds tasks in the ToDo array. Newly added tasks are immediately shown on the screen.\r\n\t\t\ttextFieldValue = \"\"; // Clears the text field so that users can start adding new tasks immediately.\r\n\t\t}\r\n\u003c/script\u003e\r\n```\r\n\r\nAdd a second/third item to the todolist and it should crash\n\n### Relevant log output (if applicable)\n\n_No response_\n\n### Environment\n\n(on another machine)\r\nNativescript Core 8.3.2\r\nPlatform iOS 13.4.1\n\n### Please accept these terms\n\n- [X] I have searched the [existing issues](https://github.com/NativeScript/NativeScript/issues) as well as [StackOverflow](https://stackoverflow.com/questions/tagged/nativescript) and this has not been posted before\n- [X] This is a bug report\n- [X] I agree to follow this project's [Code of Conduct](https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#coc)","author":{"url":"https://github.com/halfnelson","@type":"Person","name":"halfnelson"},"datePublished":"2022-08-20T01:25:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/10000/NativeScript/issues/10000"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8bd01bbe-f326-d554-6b33-1dc646a9ec7c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE94:19DD7D:209A84D:21EB8D3:6A5C8F4F |
| html-safe-nonce | bd48ab3ea7b5c861ab243d9e0f97b28ac455e7930c18ff1f9a249dc503f4b4d2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTk0OjE5REQ3RDoyMDlBODREOjIxRUI4RDM6NkE1QzhGNEYiLCJ2aXNpdG9yX2lkIjoiMTEwMDI3ODU1MTgwNTcyNjU0MyIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9 |
| visitor-hmac | 33edc554974950386f2753ad72b11b33c4342068c7202be09cb0ffc61f569a24 |
| hovercard-subject-tag | issue:1345016165 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/NativeScript/10000/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6c463fdfa0f02962b61b957fc35772ae4d78537cf12af0b78b7291bfc272c070/NativeScript/NativeScript/issues/10000 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6c463fdfa0f02962b61b957fc35772ae4d78537cf12af0b78b7291bfc272c070/NativeScript/NativeScript/issues/10000 |
| og:image:alt | Issue Description When adding multiple items to a list view at runtime, on iOS only, we get a crash: Nativescript encountered a fatal error: Uncaught TypeError: cannot read property 'removeFromSupe... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | halfnelson |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/NativeScript/NativeScript git https://github.com/NativeScript/NativeScript.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 31492490 |
| octolytics-dimension-repository_nwo | NativeScript/NativeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31492490 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/NativeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width