Skip to content

Commit 9d58900

Browse files
committed
#8149 wip
1 parent 8004744 commit 9d58900

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

apps/portal/service/Seo.mjs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ class Seo extends Base {
3434
}
3535

3636
/**
37-
* Stores the most recent route hash received from `onRouteChanged()`.
37+
* Stores the most recent route received from `onRouteChanged()`.
3838
* This is used to process a pending route update if the service becomes ready after a route change occurred.
39-
* @member {String|null} #lastRouteHash=null
39+
* @member {Object|null} #lastRouteHash=null
4040
* @private
4141
*/
42-
#lastRouteHash = null
42+
#lastRoute = null
4343
/**
4444
* Caches the SEO metadata fetched from `apps/portal/resources/data/seo.json`.
4545
* This object maps route hash strings to their corresponding title and description.
@@ -57,8 +57,8 @@ class Seo extends Base {
5757
* @protected
5858
*/
5959
afterSetIsReady(value, oldValue) {
60-
if (value && this.#lastRouteHash) {
61-
this.#updateDocumentHeadIfNeeded(this.#lastRouteHash)
60+
if (value && this.#lastRoute) {
61+
this.#updateDocumentHeadIfNeeded(this.#lastRoute)
6262
}
6363
}
6464

@@ -86,7 +86,7 @@ class Seo extends Base {
8686
if (!response.ok) {
8787
throw new Error(`HTTP error with status: ${response.status}`)
8888
}
89-
this.#metadata = await response.json();
89+
this.#metadata = await response.json()
9090
} catch (error) {
9191
console.error('Error fetching SEO metadata:', error)
9292
}
@@ -97,11 +97,13 @@ class Seo extends Base {
9797
* This method stores the new route hash and attempts to update the document head.
9898
* If the service is not yet ready (i.e., `initAsync` is still running), the update
9999
* is deferred until `isReady` becomes true.
100-
* @param {String} hash The new route hash string.
100+
* @param {Object} config The configuration object.
101+
* @param {String} config.hash The new route hash string.
102+
* @param {String} config.windowId The windowId matching the route.
101103
*/
102-
onRouteChanged(hash) {
103-
this.#lastRouteHash = hash;
104-
this.#updateDocumentHeadIfNeeded(hash)
104+
onRouteChanged(config) {
105+
this.#lastRoute = config;
106+
this.#updateDocumentHeadIfNeeded(config)
105107
}
106108

107109
/**
@@ -111,12 +113,11 @@ class Seo extends Base {
111113
* @param {Object} config The configuration object containing `description` and `title`.
112114
* @param {String} config.description The new meta-description for the document.
113115
* @param {String} config.title The new title for the document.
116+
* @param {String} config.windowId The new title for the document.
114117
* @private
115118
*/
116-
async #updateDocumentHead({description, title}) {
117-
let {windowId} = this,
118-
DocumentHead = await Neo.currentWorker.getAddon('DocumentHead', windowId);
119-
119+
async #updateDocumentHead({description, title, windowId}) {
120+
let DocumentHead = await Neo.currentWorker.getAddon('DocumentHead', windowId);
120121
await DocumentHead.update({description, title, windowId})
121122
}
122123

@@ -126,18 +127,18 @@ class Seo extends Base {
126127
* and call `#updateDocumentHead`. If an update occurs, it clears `#lastRouteHash`.
127128
* This prevents multiple updates for the same route if `onRouteChanged` is called
128129
* before `initAsync` completes.
129-
* @param {String} hash The route hash for which to update the document head.
130+
* @param {Object} config The route hash for which to update the document head.
130131
* @private
131132
*/
132-
#updateDocumentHeadIfNeeded(hash) {
133+
#updateDocumentHeadIfNeeded(config) {
133134
let me = this;
134135

135136
if (me.isReady) {
136-
let metadata = me.getMetadata(hash);
137+
let metadata = me.getMetadata(config.hashString);
137138

138139
if (metadata) {
139-
me.#updateDocumentHead(metadata);
140-
me.#lastRouteHash = null
140+
me.#updateDocumentHead({...metadata, windowId: config.windowId});
141+
me.#lastRoute = null
141142
}
142143
}
143144
}

apps/portal/view/ViewportController.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class ViewportController extends Controller {
235235
*/
236236
async onHashChange(value, oldValue) {
237237
await super.onHashChange(value, oldValue);
238-
SeoService.onRouteChanged(value?.hashString)
238+
SeoService.onRouteChanged(value)
239239
}
240240

241241
/**

src/manager/DomEvent.mjs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,16 @@ class DomEvent extends Base {
7878
* @param {Neo.component.Base} component
7979
* @param {data} event
8080
*/
81-
addResizeObserver(component, event) {
82-
if (!Neo.main.addon.ResizeObserver) {
83-
console.error('For using resize domListeners, you must include main.addon.ResizeObserver.', event)
84-
}
81+
async addResizeObserver(component, event) {
82+
let {id, windowId} = component,
83+
ResizeObserver = await Neo.currentWorker.getAddon('ResizeObserver', windowId);
8584

86-
let {id, windowId} = component;
85+
// ResizeObservers need to get registered to a specific target id
86+
if (event.delegate?.startsWith('#')) {
87+
id = event.delegate.substring(1)
88+
}
8789

88-
Neo.main.addon.ResizeObserver.register({id, windowId})
90+
ResizeObserver.register({id, windowId})
8991
}
9092

9193
/**
@@ -292,11 +294,10 @@ class DomEvent extends Base {
292294
});
293295

294296
if (localEvents.length > 0) {
295-
Neo.worker.App.promiseMessage('main', {
296-
action : 'addDomListener',
297-
appName : component.appName,
298-
events : localEvents,
299-
windowId: component.windowId
297+
Neo.worker.App.promiseMessage(component.windowId, {
298+
action : 'addDomListener',
299+
appName: component.appName,
300+
events : localEvents
300301
}).then(data => {
301302
// console.log('added domListener', data);
302303
}).catch(err => {

src/worker/Base.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class Worker extends Base {
166166
// core.Base: initRemote() subscribes to this event for the SharedWorkers context
167167
me.fire('connected');
168168

169-
me.sendMessage('main', {action: 'workerConstructed', port: id});
169+
me.sendMessage(id, {action: 'workerConstructed', port: id});
170170

171171
me.afterConnect()
172172
}
@@ -180,7 +180,7 @@ class Worker extends Base {
180180
let me = this;
181181

182182
if (!me.isSharedWorker) {
183-
me.sendMessage('main', {action: 'workerConstructed'});
183+
me.sendMessage(Neo.config.windowId, {action: 'workerConstructed'});
184184
me.afterConnect()
185185
}
186186
}

0 commit comments

Comments
 (0)