@financial-times/custom-code-component 2.0.4 → 2.0.6-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -1
- package/dist/client-metrics-adaptor.d.ts +107 -0
- package/dist/client-metrics-adaptor.js +98 -0
- package/dist/client-metrics-adaptor.js.map +1 -0
- package/dist/custom-element.d.ts +2 -3
- package/dist/custom-element.js +79 -74
- package/dist/custom-element.js.map +1 -1
- package/package.json +7 -3
- package/src/client-metrics-adaptor.ts +188 -0
- package/src/custom-code-component.ts +30 -23
|
@@ -90,6 +90,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
emitError(error: Error) {
|
|
93
|
+
console.debug("ccc#emitError", error);
|
|
93
94
|
if (error instanceof CCCError) {
|
|
94
95
|
this.dispatchEvent(
|
|
95
96
|
new ErrorEvent("ccc:error", {
|
|
@@ -122,7 +123,6 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
122
123
|
disconnectedCallback() {
|
|
123
124
|
const path = this.getAttribute("path");
|
|
124
125
|
this.log.info(`<custom-code-component:${path}> disconnected`);
|
|
125
|
-
if (typeof this.onunmount === "function") this.onunmount();
|
|
126
126
|
this.observer.disconnect();
|
|
127
127
|
}
|
|
128
128
|
|
|
@@ -130,12 +130,22 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
130
130
|
|
|
131
131
|
onmessage() {}
|
|
132
132
|
|
|
133
|
-
onunmount(
|
|
133
|
+
onunmount(e: Error) {
|
|
134
|
+
if (e instanceof Error) {
|
|
135
|
+
const renderError = new CCCRenderError(e.message, {
|
|
136
|
+
error: e,
|
|
137
|
+
component: this.component,
|
|
138
|
+
});
|
|
139
|
+
requestAnimationFrame(() => {
|
|
140
|
+
this.emitError(renderError);
|
|
141
|
+
this.unmount(renderError);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
134
145
|
|
|
135
146
|
async onready(app: Promise<void>) {
|
|
136
147
|
try {
|
|
137
148
|
await app;
|
|
138
|
-
|
|
139
149
|
this.dispatchEvent(
|
|
140
150
|
new CCCReadyEvent({
|
|
141
151
|
component: this.component,
|
|
@@ -237,26 +247,24 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
237
247
|
);
|
|
238
248
|
}
|
|
239
249
|
|
|
240
|
-
const {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
) || {};
|
|
256
|
-
|
|
257
|
-
if (unmount) this.onunmount = unmount;
|
|
250
|
+
const { onmessage, ready = Promise.resolve() } =
|
|
251
|
+
this.app(
|
|
252
|
+
shadow,
|
|
253
|
+
{
|
|
254
|
+
...(data ?? extraProps),
|
|
255
|
+
data: data ?? extraProps,
|
|
256
|
+
port: this.channel.port2,
|
|
257
|
+
tracking: this.tracking,
|
|
258
|
+
prerendered: !!prerendered,
|
|
259
|
+
children: this.children,
|
|
260
|
+
},
|
|
261
|
+
ssr,
|
|
262
|
+
this.onunmount.bind(this)
|
|
263
|
+
) || {};
|
|
264
|
+
|
|
258
265
|
if (onmessage) this.onmessage = onmessage;
|
|
259
|
-
|
|
266
|
+
|
|
267
|
+
this.onready(ready);
|
|
260
268
|
}
|
|
261
269
|
} catch (err) {
|
|
262
270
|
this.log.info(
|
|
@@ -272,7 +280,6 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
272
280
|
// Replace shadow root with either <slot> or template[data-component-fallback]
|
|
273
281
|
// slot on failure
|
|
274
282
|
unmount(e: Error) {
|
|
275
|
-
this.onunmount(e);
|
|
276
283
|
const template =
|
|
277
284
|
this.querySelector<HTMLTemplateElement>(
|
|
278
285
|
"template[data-component-fallback]"
|