From 73c54e4e8a970ac78481e4519dc02f89e4ec82eb Mon Sep 17 00:00:00 2001 From: pjanik Date: Mon, 29 Jan 2024 23:41:44 +0900 Subject: [PATCH] fix: fix report-item layout script timing issues [PT-186921649] --- .../components/report-item/report-item.tsx | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/packages/tecrock-table/src/components/report-item/report-item.tsx b/packages/tecrock-table/src/components/report-item/report-item.tsx index 73d895cc..806b1e11 100644 --- a/packages/tecrock-table/src/components/report-item/report-item.tsx +++ b/packages/tecrock-table/src/components/report-item/report-item.tsx @@ -17,37 +17,35 @@ import classMap from "../table.scss"; // this specific case. const reportItemScript = ""; @@ -62,12 +60,16 @@ export const reportItemHandler: IGetReportItemAnswerHandler, inlineCss, classMap - ); + ) + + // Add a stringified script tag to the end of the HTML string. It's important to do it after the closing body tag, + // because otherwise the script will be executed before the table is rendered. That way we can avoid using + // DOM mutation observers to detect when the table is rendered or relying on other callbacks or timing tricks. + reportItemScript; + items.push({type: "html", html: htmlWithInlineStyles}); sendReportItemAnswer({version, platformUserId, items, itemsType}); } else {