flixlix / power-flow-card-plus

A power distribution card inspired by the official Energy Distribution card for Home Assistant
548 stars 66 forks source link

Potential fix for not running on old iOS #414

Open cburn opened 10 months ago

cburn commented 10 months ago

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?

flixlix commented 9 months ago

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

Yorkie71 commented 9 months ago

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!

flixlix commented 5 months ago

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

steveworkman commented 2 months ago

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