-
Notifications
You must be signed in to change notification settings - Fork 7.7k
AppInit.appReady fires before document is loaded #1526
Comments
|
@jdiehl, I'm curious what makes the initially open document special? currentDocument could change again at any time, so won't you have to listen to currentDocumentChange and detach/reattach listeners anyway? Also, bear in mind there's no guarantee there will be any currentDocument on load -- sometimes, the user has no documents open at all when they re-launch Brackets. |
@jason-sanjose, I haven't tested this extensively - it just didn't occur with the earlier builds (luck?) @peterflynn, this is needed if your initialization code depends on the current document but you do not want that code to be triggered multiple times. Live-Development's autoconnect function uses this and the work-around is fairly ugly (see commit 35a1071). Maybe this is a border-case, and there is no need to change this. |
Reviewed - labeled medium priority since it was recently added. |
@jdiehl: I think I'm still confused :-) If your code depends on the current document, your initialization would look something like this, right?
Would anything need to change about that code if your init runs before the first "current document" is loaded? It seems like it'd still work fine as-is. (You could maybe even simplify it by removing the 'if' in that case, but it seems safer not to bank on that). |
Are you 100% certain that currentDocumentChange always fires after appReady? I remember vaguely that I had problems with that in the past. |
If you're seeing a case where currentDocumentChange, doesn't fire when something is opened, definitely file a bug. (The only case you shouldn't get that event during app load is when there is no initially open document). |
@peterflynn The idea seems to be that if Brackets starts with an open document (because it was open when you closed Brackets the last time), live preview should automatically be activated again (assuming it was active when you exited). However, this activation needs to wait until that file is actually re-opened by Brackets, and should not happen for files manually opened some time after launch. @jdiehl: Even if the ready event worked like before, it is unclear what should happen if Brackets is launched with a file as a parameter (like mate foo.js, subl foo.js, etc.). I think currently this isn't possible but I think in this case the ready event should also fire AFTER the file was loaded. But then it's not the file last used for the live preview, so automatically reestablishing live preview would be inappropriate. |
I think
should be
The way it is now, |
Alright, so in Just prior to the promise being resolved, So it was only by coincidence that the document was loaded when #1854 restores the intended behavior of the ready event. I leave it up to you guys to decide whether that is good enough or whether we should add an event to detect when basically restoring the previous Brackets state is complete. |
Confirmed fixed. Assigning to @jdiehl to close. |
Works like a charm, thanks for fixing this! |
You're welcome! |
Note: per @DennisKehrig's comment, this is actually not fixed -- just much less likely due to a shift in timing. You'll only hit this bug if restoring the working set (in particular the initially open document) takes longer than loading all extensions, since the two now happen simultaneously. |
I've filed #1951 about the potential confusion with the ordering of startup (including the race condition here). |
will result in:
If I remember correctly, brackets.ready behaved differently and waited for the document to load before firing. It is very useful to have an entry point into the app where everything (including the document) is loaded. Currently, the only work-around, I could find, is to attach a handler to DocumentManager.currentDocumentChange and detach it after a little while (this is clearly not a good way to do it).
Could we either get a new ready function that fires when the document is loaded or change appReady accordingly?
The text was updated successfully, but these errors were encountered: