Skip to content

Commit da2169f

Browse files
committed
fix: LivePreview incorrect popout URL and SharedWorker routing issues (#9518)
1 parent 52349f6 commit da2169f

8 files changed

Lines changed: 66 additions & 25 deletions

File tree

src/code/LivePreview.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class LivePreview extends Container {
220220
*/
221221
beforeSetWindowUrl(value, oldValue) {
222222
if (value.startsWith('./')) {
223-
let appPath = Neo.config.appPath.split('/');
223+
let appPath = (Neo.windowConfigs?.[this.windowId]?.appPath || Neo.config.appPath).split('/');
224224
appPath.pop()
225225

226226
return new URL(Neo.config.basePath + appPath.join('/') + value.substring(1), location.href).href

src/component/Circle.mjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,27 @@ class Circle extends Component {
216216
me.update()
217217
}
218218

219+
/**
220+
* Triggered after the windowId config got changed
221+
* @param {Number|String|null} value
222+
* @param {Number|String|null} oldValue
223+
* @protected
224+
*/
225+
afterSetWindowId(value, oldValue) {
226+
super.afterSetWindowId(value, oldValue);
227+
228+
if (value) {
229+
let appConfig = Neo.windowConfigs?.[value] || Neo.config;
230+
231+
if (this.backsideIconPath === Neo.config.resourcesPath + 'images/circle/') {
232+
this.backsideIconPath = appConfig.resourcesPath + 'images/circle/';
233+
}
234+
if (this.itemImagePath === Neo.config.resourcesPath + 'examples/images/') {
235+
this.itemImagePath = appConfig.resourcesPath + 'examples/images/';
236+
}
237+
}
238+
}
239+
219240
/**
220241
* Triggered after the draggable config got changed
221242
* @param {Boolean} value

src/component/Gallery.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ class Gallery extends Component {
407407

408408
vdomItem.id = me.getItemVnodeId(me.getRecordId(record));
409409

410-
imageVdom.src = Neo.config.resourcesPath + 'examples/' + record.image;
410+
let appConfig = Neo.windowConfigs?.[me.windowId] || Neo.config;
411+
imageVdom.src = appConfig.resourcesPath + 'examples/' + record.image;
411412

412413
imageVdom.style.height = me.itemHeight + 'px';
413414
imageVdom.style.width = me.itemWidth + 'px';

src/component/Helix.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,8 @@ class Helix extends Component {
448448
super.afterSetWindowId(value, oldValue);
449449

450450
if (value) {
451-
this.imageSource = Neo.config.resourcesPath + 'examples/'
451+
let appConfig = Neo.windowConfigs?.[value] || Neo.config;
452+
this.imageSource = appConfig.resourcesPath + 'examples/'
452453
}
453454
}
454455

src/controller/Application.mjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Application extends Base {
7777
let me = this,
7878
{name} = me;
7979

80-
me.windowId = Neo.config.windowId;
80+
me.windowId = config.windowId || Neo.bootingWindowId || Neo.config.windowId;
8181

8282
Neo.apps[me.windowId] = me;
8383

@@ -132,11 +132,12 @@ class Application extends Base {
132132
*/
133133
beforeSetMainView(value, oldValue) {
134134
if (value) {
135-
let {config} = Neo,
135+
let me = this,
136+
{config} = Neo,
136137
instanceConfig = {
137-
appName : this.name,
138-
parentId: this.parentId,
139-
windowId: config.windowId
138+
appName : me.name,
139+
parentId: me.parentId,
140+
windowId: me.windowId
140141
};
141142

142143
if (config.useSSR && config.vnode) {

src/worker/App.mjs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ class App extends Base {
6363
* @protected
6464
*/
6565
themeFilesCache = []
66+
/**
67+
* Ensures we only fetch the theme-map once per worker.
68+
* @member {Boolean} themeMapFetchStarted=false
69+
* @protected
70+
*/
71+
themeMapFetchStarted = false
6672
/**
6773
* @member {String} workerId='app'
6874
* @protected
@@ -607,14 +613,18 @@ class App extends Base {
607613
onLoadApplication(data) {
608614
let me = this,
609615
{config} = Neo,
610-
{appPath} = config;
616+
windowId = data.windowId,
617+
appConfig = Neo.windowConfigs[windowId] || config,
618+
appPath = appConfig.appPath;
611619

612-
if (config.environment !== 'development') {
620+
if (appConfig.environment !== 'development') {
613621
appPath = appPath.startsWith('/') ? appPath.substring(1) : appPath
614622
}
615623

616624
me.importApp(appPath).then(module => {
625+
Neo.bootingWindowId = windowId;
617626
module.onStart();
627+
delete Neo.bootingWindowId;
618628

619629
// short delay to ensure Component Controllers are ready
620630
config.hash && me.timeout(5).then(() => {
@@ -647,29 +657,34 @@ class App extends Base {
647657
import('../manager/Window.mjs')
648658
}
649659

650-
let {config} = Neo,
660+
let me = this,
661+
{config} = Neo,
651662
{data} = msg,
652663
url = 'resources/theme-map.json';
653664

654665
Neo.windowConfigs = Neo.windowConfigs || {};
655666

656667
Neo.windowConfigs[data.windowId] = Neo.clone(data, true);
657668

658-
if (config.environment === 'development' || config.environment === 'dist/esm') {
659-
url = `../../${url}`
660-
}
669+
if (!me.themeMapFetchStarted) {
670+
me.themeMapFetchStarted = true;
661671

662-
if (config.workerBasePath?.includes('node_modules')) {
663-
url = `../../${url}`
664-
}
672+
if (config.environment === 'development' || config.environment === 'dist/esm') {
673+
url = `../../${url}`
674+
}
665675

666-
if (url[0] !== '.') {
667-
url = `./${url}`
668-
}
676+
if (config.workerBasePath?.includes('node_modules')) {
677+
url = `../../${url}`
678+
}
669679

670-
fetch(url)
671-
.then(response => response.json())
672-
.then(data => {this.createThemeMap(data)});
680+
if (url[0] !== '.') {
681+
url = `./${url}`
682+
}
683+
684+
fetch(url)
685+
.then(response => response.json())
686+
.then(data => {me.createThemeMap(data)});
687+
}
673688

674689
config.remotesApiUrl && import('../remotes/Api.mjs').then(module => module.default.load());
675690

src/worker/Base.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ class Worker extends Base {
272272
}
273273
}
274274

275-
Neo.merge(Neo.config, data)
275+
if (!Neo.config.windowId) {
276+
Neo.merge(Neo.config, data)
277+
}
276278
}
277279

278280
/**

src/worker/Manager.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ class Manager extends Base {
407407
*
408408
*/
409409
loadApplication() {
410-
this.sendMessage('app', {action: 'loadApplication' })
410+
this.sendMessage('app', {action: 'loadApplication', windowId: this.windowId})
411411
}
412412

413413
/**

0 commit comments

Comments
 (0)