Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/smooth-feet-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@mod-protocol/react": patch
"@mod-protocol/core": patch
---

fix: onload events
10 changes: 9 additions & 1 deletion packages/core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,15 @@ export class Renderer {
el: ModElement | ConditionalFlow<ModElement>,
index: number
): T | null => {
const key = index + "";
let key = index + "";

if ("onload" in el) {
if (typeof el.onload === "string") {
key += `-${el.onload}`;
} else if (typeof el.onload === "object" && "ref" in el.onload) {
key += `-${el.onload.ref}`;
}
}

if ("if" in el) {
const { if: if_, then: then_, else: else_ } = el;
Expand Down
6 changes: 4 additions & 2 deletions packages/react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ const WrappedHorizontalLayoutRenderer = <T extends React.ReactNode>(props: {
element: Extract<ModElementRef<T>, { type: "horizontal-layout" }>;
}) => {
const { component: Component, element } = props;
const { events, type, elements, ...rest } = element;
const { type, elements, ...rest } = element;
const [events] = React.useState(element.events);

React.useEffect(() => {
events.onLoad();
Expand All @@ -189,7 +190,8 @@ const WrappedVerticalLayoutRenderer = <T extends React.ReactNode>(props: {
element: Extract<ModElementRef<T>, { type: "vertical-layout" }>;
}) => {
const { component: Component, element } = props;
const { events, type, elements, ...rest } = element;
const { type, elements, ...rest } = element;
const [events] = React.useState(element.events);

React.useEffect(() => {
events.onLoad();
Expand Down