[FRONT COMPONENTS] Serialize events through the worker boundary (#17767)

- Introduces a SerializedEventData type that captures only serializable
properties from DOM/React events
- Updates `wrapEventHandler` in the host component registry to serialize
native events via serializeEvent() before passing them across the worker
boundary via postMessage, avoiding circular references and non-cloneable
DOM nodes
- Updates generated remote element event signatures to use
RemoteEvent<SerializedEventData> instead of bare RemoteEvent, giving
front-component authors typed access to event details
This commit is contained in:
Raphaël Bosi
2026-02-09 16:22:54 +01:00
committed by GitHub
parent c18726d712
commit c6d04ccced
7 changed files with 189 additions and 31 deletions
@@ -84,7 +84,9 @@ const generateCommonEventsType = (
type: (writer) => {
writer.block(() => {
for (const event of events) {
writer.writeLine(`${event}(event: RemoteEvent): void;`);
writer.writeLine(
`${event}(event: RemoteEvent<SerializedEventData>): void;`,
);
}
});
},
@@ -184,7 +186,7 @@ const generateElementDefinition = (
const eventsType = hasEvents
? useSharedEvents
? TYPE_NAMES.COMMON_EVENTS
: `{ ${component.events.map((event) => `${event}(event: RemoteEvent): void`).join('; ')} }`
: `{ ${component.events.map((event) => `${event}(event: RemoteEvent<SerializedEventData>): void`).join('; ')} }`
: TYPE_NAMES.EMPTY_RECORD;
sourceFile.addVariableStatement({
@@ -346,6 +348,11 @@ export const generateRemoteElements = (
],
});
sourceFile.addImportDeclaration({
moduleSpecifier: '../../../sdk/front-component-common/SerializedEventData',
namedImports: [{ name: 'SerializedEventData', isTypeOnly: true }],
});
const commonPropertyNames = new Set(Object.keys(commonProperties));
const componentsWithProps = prepareComponentsWithSpecificProps(
components,