Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some infinite loops #187

Merged
merged 6 commits into from
Dec 9, 2022
Merged

Fix some infinite loops #187

merged 6 commits into from
Dec 9, 2022

Conversation

lemonmade
Copy link
Member

This PR prevents a few infinite loops that could happen in @remote-ui packages related to iterating over potentially self-referencing structures. This came up in a few different places:

  • In @remote-ui/core, we try to "hot swap" function properties so that updates to functions need to be sent over the RPC bridge less often. This "hot swapping" is done recursively for props that are objects or arrays.
  • In @remote-ui/rpc, we provide a retain and release method that will iterate through deeply nested objects to retain all nested functions.

Copy link
Member

@vividviolet vividviolet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh this is awesome! Is it possible to fix this in encode/decode layer as well? Maybe I'm testing this wrong but I still get an infinite loop if I try passing in something like this:

const props = { onPress, title: "This is a button", onPress: () => console.log("click") };
const button = root.createComponent('Button', {...props, self: props});

packages/core/src/root.ts Outdated Show resolved Hide resolved
packages/core/src/root.ts Outdated Show resolved Hide resolved
packages/core/src/root.ts Show resolved Hide resolved
packages/core/src/root.ts Show resolved Hide resolved
packages/core/src/tests/root.test.ts Outdated Show resolved Hide resolved
packages/rpc/src/memory.ts Show resolved Hide resolved
packages/rpc/src/memory.ts Show resolved Hide resolved
@lemonmade
Copy link
Member Author

@vividviolet thanks for the note about encoding — I had that in a locally-applied change but I didn't bring it into this branch, will get it done. Decoding should not have any need for this, since the self-referencing structures will be stripped out during encoding.

@lemonmade lemonmade force-pushed the fix-some-infinite-loops branch from 66e8786 to b593447 Compare December 9, 2022 02:57
@github-actions

This comment has been minimized.

@lemonmade lemonmade merged commit d8e7bae into main Dec 9, 2022
@lemonmade lemonmade deleted the fix-some-infinite-loops branch December 9, 2022 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants