streaming preview beachballs when URL is supplied
I'm writing a Sublime Text plugin that opens a buffer in Marked 2's Streaming Preview, and I think I've hit a bug. When I pass plain text, everything works fine. When I pass plain text and a base URL, Marked beachballs for ~15s, or sometimes longer.
I thought it was a sandboxing issue at first, since I was running the Mac App Store version when I started coding this earlier today. But I don't think it is – it happens consistently for me across both Catalina and Big Sur, and on the unsandboxed version.
Marked version: 2.6.4
|?||Show this help|
|ESC||Blurs the current field|
|r||Focus the comment reply box|
|^ + ↩||Submit the comment|
You can use
Command ⌘ instead of
Control ^ on Mac
1 Posted by Will Angley on 16 Feb, 2021 04:26 AM
I turned on debug logging in Marked, opened up Activity Monitor, and gathered debug information while reproducing this issue:
I've attached both the spindump and the logs that Marked wrote out.
Support Staff 2 Posted by Brett on 16 Feb, 2021 01:28 PM
How are you sending the base URL? It's expecting an NSURL in the URL
pasteboard, not a plain text one. Based on the Marked logs it appears to
be processing it fine, just wondering if it's getting gummed up in the
conversion at all.
It might help me debug if you could provide me with a working example I
could run a trace on. I'm not a Python expert, so I need something I can
just run from the command line, even if it has hardcoded text and URL.
(I'm also a Sublime user, if sharing a package is easier.)
Support Staff 3 Posted by Brett on 16 Feb, 2021 01:28 PM
Also I'm excited that you're working on this, I would love a streaming
package for Sublime!
4 Posted by Will Angley on 16 Feb, 2021 08:39 PM
I'm sending the URL as an NSURL.
Am working through my employer's Open Source Releasing process now to see if I can share the package. Will reply back when I hear back from them.
Support Staff 5 Posted by Brett on 17 Feb, 2021 12:27 PM
Here's the code I'm using for testing. I only know of one other developer that has for sure integrated the base url feature, so it's entirely possible there's an edge case I'm failing to compensate for. Seeing your code might help me find it. But this works (tested with the non-MAS version):
6 Posted by Will Angley on 18 Feb, 2021 08:38 PM
Code is live now: https://github.com/willangley/PreviewInMarked
My code looks like a near equivalent of it, but I'm not exactly sure. FWIW, I've been testing with Marked open already and haven't tried adding an
7 Posted by Will Angley on 20 Feb, 2021 01:35 AM
I'm impressed by the subtlety of this. I don't have CodeRunner, but I copied the code in #5 into a new Command Line Tool in Xcode and confirmed it opened Marked and then crashed Marked immediately.
This wasn't what I was hoping for, but it wasn't a beachball, and then I realized I needed to revised the code a bit:
baseURLat a file on my system
openURLmight rely on the destination app running at the time, and commented it out
When I ran it again, it opened Marked and Marked became responsive immediately...
Support Staff 8 Posted by Brett on 20 Feb, 2021 01:45 AM
I clearly need a guard statement when reading the url…
Is it possible the sublime plugin is sending an invalid url? I haven't had a chance to actually test it out yet.
9 Posted by Will Angley on 20 Feb, 2021 06:08 PM
That's a good question – trying to answer it was revealing.
I changed the plugin to write to
[NSPasteboard generalPasteboard]and looked at the pasteboard contents in Pasteboard Viewer . When I did, I was able to access the text instantly; clicking on the file URL caused Pasteboard Viewer to hang for a while before displaying the URL.
Pasteboard Viewer did not hang when I made a similar change to the code used for testing.
Pasteboard Viewer doesn't just display file URLs; it will try to show a QuickLook preview of their contents. I'm using the Mac App Store version of this for now, so it won't actually show them even when I point to an extant path on the filesystem, but I'm guessing that trying to access the file at the URL is enough to result in a hang when it happens.
I'm not sure the root cause of the hang yet, but it's not specific to Marked.
Support Staff 10 Posted by Brett on 21 Feb, 2021 01:17 PM
Let me know if you do find the cause.
11 Posted by Will Angley on 23 Feb, 2021 06:21 AM
I did, and I was able to work around it. I've pushed an early-but-usable version to GitHub. LMK if you give it a try.
A client that reads the URL from the pasteboard may ask for alternative representations, and
pboardwill try to call back to the process that wrote the URL.
I don't control the Sublime Text plugin host, so I can't start a CFRunLoop on its main thread. But I can spawn a subprocess and start a CFRunLoop there...
Support Staff 12 Posted by Brett on 23 Feb, 2021 12:59 PM
Awesome, will try this out!
Support Staff 13 Posted by Brett on 23 Feb, 2021 01:15 PM
By the way, in case it wasn't clear, the openURL in my example code just calls the Marked URL handler for opening the streaming preview and returning focus to the originating app by bundle identifier, in that case CodeRunner. I just left it there as an example of how the plugin could open the streaming preview. You wouldn't want to call it with every update, but it might be nice when first initializing. (You may have already implemented this, I haven 't tested yet!)
Support Staff 14 Posted by Brett on 23 Feb, 2021 01:21 PM
Ok, stupid question: I should be able to just drag the PreviewInMarked folder into
Application Support/Sublime Text 3/Packagesand it should show up in the palette right? It's been a long time since I manually installed a package...
15 Posted by Will Angley on 23 Feb, 2021 06:39 PM
Thanks for trying this out! To answer your questions,
I have indeed integrated URL opening already! It's not perfect though; sometimes things load without styling or load to a blank page. Refreshing Marked should work around that. PreviewInMarked#4
That's not a stupid question, and that is indeed what you need to do. (And, if you've already got a PreviewInMarked folder locally, you should download it again – I fixed a pretty serious threading bug between then and now.)
I'm hoping to get this stable enough to ship to Package Control over the weekend, since manual installs are a lot of work. PreviewInMarked#11