@@ -3400,6 +3400,9 @@ define("JSUtils/Session", function (require, exports, module) {
34003400 * - "navigated_away" (The browser changed to a location outside of the project)
34013401 * - "detached_target_closed" (The tab or window was closed)
34023402 */
3403+
3404+ /*global jsPromise */
3405+
34033406define("LiveDevelopment/LiveDevMultiBrowser", function (require, exports, module) {
34043407
34053408
@@ -3867,24 +3870,18 @@ define("LiveDevelopment/LiveDevMultiBrowser", function (require, exports, module
38673870 isViewable = _server && _server.canServe(doc.file.fullPath);
38683871
38693872 if (_liveDocument && _liveDocument.doc.url !== docUrl && isViewable) {
3870- // clear live doc and related docs
3871- _closeDocuments();
3872- // create new live doc
3873- _createLiveDocumentForFrame(doc);
3874- _setStatus(STATUS_RESTARTING);
3875- _open(doc);
3876-
3873+ open();
38773874 }
38783875 }
38793876
38803877
38813878 /**
38823879 * Open a live preview on the current docuemnt.
38833880 */
3884- function open() {
3881+ async function open() {
38853882 let doc = DocumentManager.getCurrentDocument();
38863883 if(livePreviewUrlPinned){
3887- doc = DocumentManager.getDocumentForPath(currentPreviewFilePath);
3884+ doc = await jsPromise( DocumentManager.getDocumentForPath(currentPreviewFilePath) );
38883885 }
38893886
38903887 // wait for server (StaticServer, Base URL or file:)
@@ -3894,6 +3891,9 @@ define("LiveDevelopment/LiveDevMultiBrowser", function (require, exports, module
38943891 return;
38953892 }
38963893 _setStatus(STATUS_CONNECTING);
3894+ // clear live doc and related docs
3895+ _closeDocuments();
3896+ // create new live doc
38973897 doc && _createLiveDocumentForFrame(doc);
38983898 if(_server.isActive()){
38993899 doc && _open(doc);
@@ -7617,9 +7617,9 @@ define("LiveDevelopment/main", function main(require, exports, module) {
76177617 MultiBrowserLiveDev.close();
76187618 }
76197619
7620- function openLivePreview() {
7620+ function openLivePreview(doc ) {
76217621 if (!Phoenix.isTestWindow) {
7622- MultiBrowserLiveDev.open();
7622+ MultiBrowserLiveDev.open(doc );
76237623 }
76247624 }
76257625
@@ -37514,7 +37514,7 @@ table tr{background-color:#fff;border-top:1px solid #c6cbd1}table tr:nth-child(2
3751437514 */
3751537515
3751637516/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
37517- /*global path*/
37517+ /*global path, jsPromise */
3751837518//jshint-ignore:no-start
3751937519
3752037520define("extensionsIntegrated/Phoenix-live-preview/main", function (require, exports, module) {
@@ -38031,13 +38031,12 @@ define("extensionsIntegrated/Phoenix-live-preview/main", function (require, expo
3803138031 $highlightBtn.click(_toggleLiveHighlights);
3803238032 $livePreviewPopBtn.click(_popoutLivePreview);
3803338033 $reloadBtn.click(()=>{
38034- LiveDevelopment.openLivePreview();
38035- _loadPreview(true);
38034+ _loadPreview(true, true);
3803638035 Metrics.countEvent(Metrics.EVENT_TYPE.LIVE_PREVIEW, "reloadBtn", "click");
3803738036 });
3803838037 }
3803938038
38040- async function _loadPreview(force) {
38039+ async function _loadPreview(force, isReload ) {
3804138040 // we wait till the first server ready event is received till we render anything. else a 404-page may
3804238041 // briefly flash on first load of phoenix as we try to load the page before the server is available.
3804338042 const isPreviewLoadable = panel.isVisible() || StaticServer.hasActiveLivePreviews();
@@ -38061,6 +38060,15 @@ define("extensionsIntegrated/Phoenix-live-preview/main", function (require, expo
3806138060 currentLivePreviewURL = newSrc;
3806238061 currentPreviewFile = previewDetails.fullPath;
3806338062 }
38063+ const existingPreviewFile = $iframe && $iframe.attr('data-original-path');
38064+ const existingPreviewURL = $iframe && $iframe.attr('data-original-src');
38065+ if(isReload && previewDetails.isNoPreview && existingPreviewURL &&
38066+ existingPreviewFile && ProjectManager.isWithinProject(existingPreviewFile)) {
38067+ currentLivePreviewURL = existingPreviewURL;
38068+ currentPreviewFile = existingPreviewFile;
38069+ } else if(isReload){
38070+ LiveDevelopment.openLivePreview();
38071+ }
3806438072 let relativeOrFullPath= ProjectManager.makeProjectRelativeIfPossible(currentPreviewFile);
3806538073 relativeOrFullPath = Phoenix.app.getDisplayPath(relativeOrFullPath);
3806638074 _setTitle(relativeOrFullPath, currentPreviewFile);
@@ -38071,6 +38079,10 @@ define("extensionsIntegrated/Phoenix-live-preview/main", function (require, expo
3807138079 $iframe = newIframe;
3807238080 if(_isProjectPreviewTrusted()){
3807338081 $iframe.attr('src', currentLivePreviewURL);
38082+ // we have to save src as the iframe src attribute may have redirected, and we cannot read it as its
38083+ // a third party domain once its redirected.
38084+ $iframe.attr('data-original-src', currentLivePreviewURL);
38085+ $iframe.attr('data-original-path', currentPreviewFile);
3807438086 } else {
3807538087 $iframe.attr('srcdoc', _getTrustProjectPage());
3807638088 }
@@ -141128,18 +141140,19 @@ define("utils/StringUtils", function (require, exports, module) {
141128141140 *
141129141141 * !!!Should not be used for crypto secure workflows.!!!
141130141142 *
141131- * @param {number} stringLength - The length of the nonce in bytes.
141143+ * @param {number} stringLength - The length of the nonce in bytes. default 10.
141144+ * @param {string} [prefix] - optional prefix
141132141145 * @returns {string} - The randomly generated nonce.
141133141146 */
141134- function randomString(stringLength) {
141147+ function randomString(stringLength=10, prefix="" ) {
141135141148 const randomBuffer = new Uint8Array(stringLength);
141136141149 crypto.getRandomValues(randomBuffer);
141137141150
141138141151 // Define the character set for the random string
141139141152 const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
141140141153
141141141154 // Convert the ArrayBuffer to a case-sensitive random string with numbers
141142- let randomId = '';
141155+ let randomId = prefix || '';
141143141156 Array.from(randomBuffer).forEach(byte => {
141144141157 randomId += charset[byte % charset.length];
141145141158 });
0 commit comments