Wp-calypso: Get rid of isMounted

Created on 17 Oct 2017  ยท  6Comments  ยท  Source: Automattic/wp-calypso

this.isMounted() is a deprecated feature and was removed in React 16.

At best we can semantically remove all usages of isMounted() throughout the codebase.

At worst, we can at least simulate having an isMounted() function by creating our own variable for it that gets set in componentWillMount() and componentWillUnmount()

edit from oct 20th: this actually isn't necessary for the React 16 upgrade because createReactClass still supports it

Framework Simple Payments [Type] Janitorial

Most helpful comment

  • [x] reader/tag-stream/main.jsx:5 (@blowery - uses an internal isMounted)
  • [x] blocks/daily-post-button/index.jsx:4 (@blowery - uses an internal isMounted)
  • [ ] my-sites/draft/index.jsx:2
  • [ ] my-sites/checkout/cart/popover-cart.jsx:1
  • [x] components/tinymce/plugins/simple-payments/dialog/index.jsx:6 (@blowery - uses an internal isMounted)
  • [ ] components/olark-chatbox/index.jsx:1
  • [x] components/domains/register-domain-step/index.jsx:4 (@blowery - uses an internal isMounted)
  • [ ] components/stat-update-indicator/index.jsx:1
  • [ ] components/infinite-list/index.jsx:3
  • [x] components/token-field/token-input.jsx:2 (#19003)
  • [x] me/two-step/index.jsx:1 (@blowery - commented out)
  • [ ] post-editor/media-modal/gallery/preview-shortcode.jsx:1
  • [x] lib/accept/dialog.jsx:1 (#19000)

All 6 comments

Thankfully, not too much usage for us:

โฏ ag --count isMounted
reader/tag-stream/main.jsx:5
blocks/daily-post-button/index.jsx:4
my-sites/draft/index.jsx:2
my-sites/checkout/cart/popover-cart.jsx:1
components/tinymce/plugins/simple-payments/dialog/index.jsx:6
components/olark-chatbox/index.jsx:1
components/domains/register-domain-step/index.jsx:4
components/stat-update-indicator/index.jsx:1
components/infinite-list/index.jsx:3
components/token-field/token-input.jsx:2
me/two-step/index.jsx:1
post-editor/media-modal/gallery/preview-shortcode.jsx:1
lib/accept/dialog.jsx:1

Also need to check our deps in node_modules... but hopefully they'll declare compat with react@16?

  • [x] reader/tag-stream/main.jsx:5 (@blowery - uses an internal isMounted)
  • [x] blocks/daily-post-button/index.jsx:4 (@blowery - uses an internal isMounted)
  • [ ] my-sites/draft/index.jsx:2
  • [ ] my-sites/checkout/cart/popover-cart.jsx:1
  • [x] components/tinymce/plugins/simple-payments/dialog/index.jsx:6 (@blowery - uses an internal isMounted)
  • [ ] components/olark-chatbox/index.jsx:1
  • [x] components/domains/register-domain-step/index.jsx:4 (@blowery - uses an internal isMounted)
  • [ ] components/stat-update-indicator/index.jsx:1
  • [ ] components/infinite-list/index.jsx:3
  • [x] components/token-field/token-input.jsx:2 (#19003)
  • [x] me/two-step/index.jsx:1 (@blowery - commented out)
  • [ ] post-editor/media-modal/gallery/preview-shortcode.jsx:1
  • [x] lib/accept/dialog.jsx:1 (#19000)

Did a quick check on what I found using isMounted and made up a check list. The stuff left needs to be fixed.

After further research, it looks like isMounted() is still supported when using createReactClass. While it will be good to fix them all, I'd consider it to be part of the "Backburner" category now and shouldn't be seen as necessary on the road to 16

only cases left are:

  • client/my-sites/draft/index.jsx
  • client/my-sites/checkout/cart/popover-cart.jsx
  • client/components/infinite-list/index.jsx
  • client/me/two-step/index.jsx
  • client/post-editor/media-modal/gallery/preview-shortcode.jsx

I'm closing this Issue though because there is no pressing need to fix them

Was this page helpful?
0 / 5 - 0 ratings