power-flow-card-plus icon indicating copy to clipboard operation
power-flow-card-plus copied to clipboard

Potential fix for not running on old iOS

Open cburn opened this issue 1 year ago • 4 comments

I have a potential fix for bug #150.

The card is failing to load on on old iOS devices as Safari/Webkit only supported the nullish coalescing operator '??' from iOS version 13.4.

I searched the installed www/community/power-flow-card-plus/power-flow-card-plus.js file for instances of "??" and there were 2 places where it appeared.

I edited super(a ?? l) to super(( a != null ) ? a : l) and o ?? (o = [e, ...t()]) to (o != null) ? o : (o = [e, ...t()]) in place and deleted the .gz version of the file, and it works perfectly on an old iPad mini running iOS 12.5.7

Sorry I don't know how to fix this in your code/release process but hopefully this points the right direction. Maybe some options to send through babel to target older browsers?

cburn avatar Nov 02 '23 14:11 cburn

Thanks for the hint, I'll check it out 👍

flixlix avatar Nov 08 '23 07:11 flixlix

This is great to see as I have HA running on an old iPad in the kitchen and it works fine but since Power Card Plus has been the primary card on the main dashboard, it's not worked on the iPad so hopefully this means that the old tech has a future again!

Yorkie71 avatar Nov 23 '23 07:11 Yorkie71

Can you check if this fixes the issue, there are still two ?? in there, but maybe it's fixed now power-flow-card-plus.js.zip

Edit: please make sure in the console shows the version 0.2.0-414 to make sure you are using the correct version

flixlix avatar Mar 26 '24 17:03 flixlix

I've had a look deeper in the code at this (I'm pretty new to HA and am using an old iPad in the kitchen too!).

The issue comes from superstruct where this.failures is a function with a nullish operator inside. This is because the node modules aren't being transpiled with iOS 12 as a target, just to the current version of node.

So: babel.config.js gets ["@babel/preset-env", { targets: { node: "current", ios: "12" } }] and the rollup.config.js gets:

babel({
        exclude: /node_modules\/(?!superstruct)\/.*/,
        babelHelpers: "bundled",
      }),

I'll send over a PR

steveworkman avatar Jun 06 '24 21:06 steveworkman