Page MenuHomePhabricator

CodeMirror breaks on some large RTL pages
Open, LowPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

What happens?:

Eventually everything is either highlighted as green (same color tags are supposed to have), or purple (templates). Or, you may see no highlighting at all.

With bidi isolation applied (T358804), CodeMirror may error out entirely:

Uncaught TypeError: Cannot read properties of undefined (reading 'length')

What should have happened instead?:

Syntax highlighting should work as expected.

Other information:

This is a rather extreme example, being one of the largest articles on Arabic Wikipedia. Maybe things breaking is expected here.

What we should prevent however are the errors that can happen. Perhaps automatically disable CodeMirror due to performance reasons and show a message stating such, or something?

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Replacing all content with more RTL content (LTR seems fine for some reason?) puts CodeMirror in a broken state, and might even produce errors

I have confirmed T358804 to be the apparent cause of the errors. With older commits, the syntax highlighting is still broken, but it doesn't error out.

I'll investigate further and return here with my findings and/or a patch. I had a feeling bidi isolation could cause some problems, which is why I was planning on putting behind a preference when we tackle T359498. I think it's fine if it doesn't work occasionally, but it should never error out and prevent editing.

Seems there may a direct correlation of article size to performance and potential for errors. From cursory testing on Arabic Wikipedia's largest articles:

I do see the warning "Measure loop restarted more than 5 times" when scrolling quickly, but as I understand this is somewhat expected, and doesn't seem to be causing any real problems.

Perhaps the highlighting being broken is okay for the extreme cases? I think my goal may be only to prevent the errors, which might be as simple as a try/catch block around the bidi isolation code.

Doesn't seem to be a deal-breaker. I'm removing this off CommTech's radar for the time being. As we rollout to more RTL wikis, it's possible we'll need to revisit this.

Indeed! r1031962 seems to fix a lot of the issues, but not all of them. Line 697 of برنامج الصواريخ الإيرانية for example still shows broken highlighting. I am no longer seeing errors, though (even without r1031962), so we're certainly headed in the right direction :)

I am content with the breakage at "برنامج الصواريخ الإيرانية ", given it is an extreme example. CM5 didn't support RTL, but I highly suspect if it did it would have many of the same problems for this particular article.

Line 697 of برنامج الصواريخ الإيرانية for example still shows broken highlighting.

Thanks for reporting this! However, this may be something we expect because the parser does not know that the template has been closed after the point where it stops highlighting on Line 697.