github / Rebel

Cocoa framework for improving AppKit
Other
1.13k stars 112 forks source link

RBLHTMLView spinning the run loop #110

Open alanjrogers opened 11 years ago

alanjrogers commented 11 years ago

https://github.com/github/Rebel/blob/master/Rebel/RBLHTMLView.m#L118-L120

RBLHTMLView spins the current run loop while it waits for the HTML to render.

I haven't dug into it too far yet, but I've seen this cause an intermittent crash if the HTML for the view has been assigned inside of a 'transaction' such as the begin/endUpdates calls used in view based NSTableViews.

For example:

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
    if ((NSUInteger)row >= self.cellCount) return nil;

    if (row == 0) {
       MYCellView *cellView = [[MYCellView alloc] initWithNibName:@"MYCellView" bundle:nil];
         cellView.rblHTMLView = self.htmlString;
    }
}

This method is called when rows are inserted into the table view, so usually after a call to [tableView beginUpdates]. My theory is that spinning the run loop is implicitly calling endUpdates resulting in unbalanced calls.

jspahrsummers commented 11 years ago

I think this is done to avoid a flash when the page reloads (by simply not returning control to the renderer until the page is ready).

Maybe we could instead do this in a block asynchronously dispatched to the main thread. It'd introduce an imperceptible delay before starting to render, but would ensure that it occurs outside of any transactional behavior.

joshaber commented 11 years ago

This was to ensure that it rendered the new content as soon as it was set, as you'd expect a label to do. Introducing a queue hop doesn't seem like it'd solve the problem :\