JavaScript code using optional chaining doesn't work on older devices
-
I'm working on a plugin. Today I noticed that my development site doesn't work at all on an Android phone with Marshmallow. Turns out there were instances of "?." in nodebb.min.js that the older version of Chrome couldn't handle. I had thought that these would get transpiled away but doesn't seem to be the case. Is this intended behavior? I'm developing against v.3.0.0 RC1.
-
@chung-leong Hm, I'm not actually sure. @baris would know best, but I don't believe our webpack configuration does any transpilation for backwards compatibility.
That said, I'm pretty sure there aren't any
?.
in the core or bundled plugins, if only because ESLint would complain since that isn't currently allowed yet Are they in your plugin? -
I was using the feature, but nodebb.min.js is pulling the code from a couple of the libraries used by NodeBB.
I tracked one instance tonode_modules/clipboard/src/actions/copy.js
. The distribution files of clipboard have optional chaining transpiled out, but I guess NodeBB is importing the original modules. -
Actually I managed to get it to work on the phone by upgrading Chrome. According to caniuse, optional chaining became available in Chrome 80. In theory compatibility should extend all the way down to Kitkat. The lack of transpiling is a bit concerning though.