[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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user