jupyter-widgets / ipydatagrid

Fast Datagrid widget for the Jupyter Notebook and JupyterLab
BSD 3-Clause "New" or "Revised" License
580 stars 51 forks source link

Does not render in Safari #284

Open mangecoeur opened 2 years ago

mangecoeur commented 2 years ago

I cannot get ipydatagrid to render at all in Safari. Checking the console I see this error:

Unhandled Promise Rejection: Error: Module ipydatagrid, semver range ^1.1.7 is not registered as a widget module
promiseEmptyOnRejected — 523.fa256ee012d38a89b65a.js:1:6648
promiseReactionJob
272.2a8425db7209008188fc.js:1:2113

No idea why data grid fails to be registered in Safari only (no problem on Firefox of Chrome-based browsers).

The same problem appears on iPads (which is a shame because iPads are a nice way to show off demos!)

ibdafna commented 2 years ago

Hello :wave: @mangecoeur! Many thanks for reporting this.

It is difficult for me to test on Safari because Apple does not make it easy to run Safari on non-Mac machines, and I develop primarily on a Linux machine. I tried before but there isn't a straightforward way of running Safari on my machine unfortunately - it's either a paid service like BrowserStack or a VM of an old MacOS image. It would be great if someone from the community could help me with this - I'm happy to mentor and guide through the codebase whoever takes this up 😸

Other than that, I'll try to borrow a machine from a colleague in the new year and test there.

mangecoeur commented 2 years ago

Yes it's a pain testing apple things without a machine. I'm ultra busy wrapping up end-of-year things, if I find some time I will try to have a look - I suspect it's a build/packaging issue but I don't know why it would affect safari only.

martinRenou commented 2 years ago

@mangecoeur do you see another error earlier in the stack? There might be more information there that could help us understand why the extension failed to activate.

mangecoeur commented 2 years ago

@martinRenou I'm going to make a clean fork and see if i get some more informative errors

mangecoeur commented 2 years ago

Example notebook in Jupyterlab in Safari. First cell:

from ipydatagrid import DataGrid, TextRenderer, BarRenderer, Expr

Gives console errors:

[Error] Could not instantiate widget
    (anonymous function) (272.9d70a85a9abe209402d0.js:1:9460)
    (anonymous function) (272.9d70a85a9abe209402d0.js:1:5994)
    l (272.9d70a85a9abe209402d0.js:1:4884)
    promiseReactionJob
[Error] Error: Could not create a model. — 272.9d70a85a9abe209402d0.js:0
    (anonymous function) (272.9d70a85a9abe209402d0.js:1:2113)
    promiseReactionJob
[Error] Exception opening new comm
    (anonymous function) (jlab_core.acade4bce7efaf6825f2.js:2:940002)
    asyncFunctionResume
    (anonymous function)
    promiseReactionJobWithoutPromise
    promiseReactionJob
[Error] Unhandled Promise Rejection: Error: Module ipydatagrid, semver range ^1.1.8 is not registered as a widget module
    promiseEmptyOnRejected (523.cf94b68f6edde7eefd61.js:1:6647)
    promiseReactionJob
[Error] Could not instantiate widget
    (anonymous function) (272.9d70a85a9abe209402d0.js:1:9460)
    (anonymous function) (272.9d70a85a9abe209402d0.js:1:5994)
    l (272.9d70a85a9abe209402d0.js:1:4884)
    promiseReactionJob
[Error] Error: Could not create a model. — 272.9d70a85a9abe209402d0.js:0
    (anonymous function) (272.9d70a85a9abe209402d0.js:1:2113)
    promiseReactionJob
[Error] Exception opening new comm
    (anonymous function) (jlab_core.acade4bce7efaf6825f2.js:2:940002)
    asyncFunctionResume
    (anonymous function)
    promiseReactionJobWithoutPromise
    promiseReactionJob
[Error] Unhandled Promise Rejection: Error: Module ipydatagrid, semver range ^1.1.8 is not registered as a widget module
    promiseEmptyOnRejected (523.cf94b68f6edde7eefd61.js:1:6647)
    promiseReactionJob
mangecoeur commented 2 years ago

Tried having a look at what's going on but debugging typescript/javascript is not my thing. What I was able to find out is that ipydatagrid does not appear in the jupyterlab module registry in safari, but I couldn't figure out how to trace where it should be registered in the first place :/

One thing I'd like to clarify though, I'm not sure I correctly rebuild the extension. I followed the instructions on the readme, changed the version number in package.json to 1.1.9 and ran jupyter labextension build --dev-build. But when I see the error in the console it still says semver range ^1.1.8 so I'm not sure I'm doing it right.

jasongrout commented 2 years ago

I saw today that there was an error at the very top of the Safari error console that there was a problem with a regular expression. It reminded me of https://github.com/jupyterlab/jupyterlab/issues/9961, in which we found that Safari did not support a regular expression syntax many other browsers support: https://caniuse.com/js-regexp-lookbehind

Indeed, I find that syntax here in ipydatagrid: https://github.com/bloomberg/ipydatagrid/blob/1f25bf44def4485936ee6c1e50e76d58df295f8f/js/vegaexpr.ts#L80

CC @ibdafna

ibdafna commented 2 years ago

@jasongrout Ah, that must be it! Thanks for figuring this out ❤️. I suppose we'll need alternative logic to replace the lookbehind regex (why is this not implemented in Safari 😒). I'll update here when it's fixed.

mangecoeur commented 2 years ago

Putting this link for references, will try to implement if i find time https://stackoverflow.com/questions/7376238/javascript-regex-look-behind-alternative

mangecoeur commented 2 years ago

Thanks to @jasongrout insight, was able to replace the lookbehind and now it works in Safari!

ibdafna commented 2 years ago

Closed via #353 Thanks again @mangecoeur ☺