ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.59k stars 335 forks source link

Basic example broken inside of the shadow dom (Chrome, Firefox, Safari) #1413

Closed TehShrike closed 1 year ago

TehShrike commented 1 year ago

Here's a repo with the reproduction.

Check out the reproduction in your browser now.

Here is the relevant code.

There's some more information about how the prosemirror modules were bundled in the readme.

This is the broken stuff I've noticed so far:

marijnh commented 1 year ago

Attached patch should fix the icons.

I do not see any of the other issues in my browser—I can ctrl-shift-arrow select just fine on Firefox, and don't see any difference in box size on Chrome.

TehShrike commented 1 year ago

hm, the large editor box only replicates locally for me, not when I load the same code from github.io. I'll have to poke more at that to see if I can figure out more.

On the cmd+shift+arrow issue – I'm guessing you're on Windows? I'm on macOS 13.5 at the moment. On macOS, Cmd+left and Cmd+right are the equivalent of home and end on Windows, so maybe you'd be able to replicate it with shift+home/shift+end. Or maybe it's a mac-only bug :-x

TehShrike commented 1 year ago

Some more information about the large editor box issue: in Chrome, something is manually setting a min-height: 1447px on the menubar element:

CleanShot 2023-08-14 at 09 26 36@2x

in Safari, the min-height is being manually set on the element to 1446px.

Safari shows the style element flashing when I scroll, which implies that something is changing that attribute then.

TehShrike commented 1 year ago

If I remove this line, everything seems to work fine as far as the menubar size is concerned: https://github.com/ProseMirror/prosemirror-menu/blob/bee0a10a2082f28bb4c63c4ef17c275479fb05c9/src/menubar.ts#L85

I have no idea why the menu offsetHeight reads a large number briefly when the page is first being rendered. (Let alone why it only happens on localhost/127001 inside of a shadow dom 🙃)

TehShrike commented 1 year ago

Another clue on the Firefox cmd+arrow front – outside the shadow dom, pressing cmd+left inside of prosemirror moves the cursor to the beginning of the line. Inside the shadow dom, cmd+left inside of prosemirror triggers Firefox's stupid "navigate to the previous page in the browser history" shortcut.

marijnh commented 1 year ago

Right, I was indeed using Linux, not macOS.

That seems to be a Firefox bug, though—the handling for shift-cmd-left (and cmd-left) doesn't seem to realize the cursor is in a text field. When you do ctrl-left it'll go back in the browser history. ProseMirror leaves these kind of cursor motion keys to the browser, since the native behavior does a better job on things like bidi text, weird layouts, and conforming to platform-specific expectations than a custom implementation would. As such, I consider this a browser issue, outside of the library's scope.

TehShrike commented 1 year ago

All right, I'll try to open a ticket in the Firefox bug tracker for that.

What about the offsetHeight bug when browsing localhost + Chrome/Safari?

marijnh commented 1 year ago

What about the offsetHeight bug when browsing localhost + Chrome/Safari?

I haven't been able to reproduce that. In any case, it sounds more likely to be a CSS issue than a ProseMirror issue.

TehShrike commented 1 year ago

Occasionally giant menu bar: It's related to this menubar code – if anything causes the menu's offsetHeight to be unusually large for one tick, setting the minHeight prevents it from ever adjusting back down.

TehShrike commented 1 year ago

Firefox bug with keypresses in contenteditable in shadow dom: Here is the bugzilla issue I opened.

marijnh commented 1 year ago

if anything causes the menu's offsetHeight to be unusually large for one tick,

Do you know what's causing it to be large? Is that related to the asynchronous loading of the CSS code?

maxweber commented 11 months ago

I had the same problem, and it was due to the asynchronous loading of the CSS code.