Skip to content

Commit

Permalink
fix: 1.live preview start speed, 2.flicker 3.not showing in untrusted…
Browse files Browse the repository at this point in the history
… projects
  • Loading branch information
abose committed Jan 6, 2024
1 parent 272bd94 commit 0cb44af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/extensions/default/Phoenix-live-preview/StaticServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ define(function (require, exports, module) {
const EVENT_TAB_ONLINE = 'TAB_ONLINE';
const EVENT_REPORT_ERROR = 'REPORT_ERROR';
const EVENT_UPDATE_TITLE_ICON = 'UPDATE_TITLE_AND_ICON';
const EVENT_SERVER_READY = 'SERVER_READY';

EventDispatcher.makeEventDispatcher(exports);
const PHCODE_LIVE_PREVIEW_QUERY_PARAM = "phcodeLivePreview";
Expand Down Expand Up @@ -569,4 +570,5 @@ define(function (require, exports, module) {
exports.getTabPopoutURL = getTabPopoutURL;
exports.hasActiveLivePreviews = hasActiveLivePreviews;
exports.PHCODE_LIVE_PREVIEW_QUERY_PARAM = PHCODE_LIVE_PREVIEW_QUERY_PARAM;
exports.EVENT_SERVER_READY = EVENT_SERVER_READY;
});
28 changes: 12 additions & 16 deletions src/extensions/default/Phoenix-live-preview/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ define(function (require, exports, module) {
const PREVIEW_TRUSTED_PROJECT_KEY = "preview_trusted";
const moduleDir = FileUtils.getNativeModuleDirectoryPath(module);

const LIVE_PREVIEW_PANEL_ID = "live-preview-panel",
IFRAME_EVENT_SERVER_READY = 'SERVER_READY';
let serverReady = false;
const LIVE_PREVIEW_PANEL_ID = "live-preview-panel";
const LIVE_PREVIEW_IFRAME_HTML = `
<iframe id="panel-live-preview-frame" title="Live Preview" style="border: none"
width="100%" height="100%" seamless="true"
Expand Down Expand Up @@ -285,7 +283,7 @@ define(function (require, exports, module) {
async function _loadPreview(force) {
// we wait till the first server ready event is received till we render anything. else a 404-page may
// briefly flash on first load of phoenix as we try to load the page before the server is available.
const isPreviewLoadable = serverReady && (panel.isVisible() || StaticServer.hasActiveLivePreviews());
const isPreviewLoadable = panel.isVisible() || StaticServer.hasActiveLivePreviews();
if(!isPreviewLoadable){
return;
}
Expand Down Expand Up @@ -395,15 +393,7 @@ define(function (require, exports, module) {
let fileMenu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU);
fileMenu.addMenuItem(Commands.FILE_LIVE_FILE_PREVIEW, "", Menus.AFTER, Commands.FILE_EXTENSION_MANAGER);
fileMenu.addMenuDivider(Menus.BEFORE, Commands.FILE_LIVE_FILE_PREVIEW);
// We always show the live preview panel on startup if there is a preview file
setTimeout(async ()=>{
LiveDevelopment.openLivePreview();
let previewDetails = await utils.getPreviewDetails();
if(previewDetails.filePath){
// only show if there is some file to preview and not the default no-preview preview on startup
_setPanelVisibility(true);
}
}, 1000);
LiveDevelopment.openLivePreview();
LiveDevelopment.on(LiveDevelopment.EVENT_OPEN_PREVIEW_URL, _openLivePreviewURL);
LiveDevelopment.on(LiveDevelopment.EVENT_LIVE_HIGHLIGHT_PREF_CHANGED, _updateLiveHighlightToggleStatus);
LiveDevelopment.on(LiveDevelopment.EVENT_LIVE_PREVIEW_RELOAD, ()=>{
Expand All @@ -414,9 +404,15 @@ define(function (require, exports, module) {
// required in chrome, but we just keep it just for all platforms behaving the same.
_loadPreview(true);
});
StaticServer.on(IFRAME_EVENT_SERVER_READY, function (_evt, event) {
serverReady = true;
_loadPreview(true);
StaticServer.on(StaticServer.EVENT_SERVER_READY, function (_evt, event) {
// We always show the live preview panel on startup if there is a preview file
utils.getPreviewDetails().then(previewDetails =>{
if(previewDetails.filePath){
// only show if there is some file to preview and not the default no-preview preview on startup
_setPanelVisibility(true);
_loadPreview(true);
}
});
});

let consecutiveEmptyClientsCount = 0;
Expand Down

0 comments on commit 0cb44af

Please sign in to comment.