Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/fair-islands-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@builder.io/sdk-react-native": patch
---

Added deep memo comparison using react-fast-compare.
14 changes: 11 additions & 3 deletions packages/sdks/mitosis.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,20 @@ const MEMOIZING_BLOCKS_COMPONENT_PLUGIN = () => ({
imports: { memo: 'memo' },
path: 'react',
});
json.imports.push({
imports: { isEqual: 'default' },
path: 'react-fast-compare',
});
}
if (json.name === 'Blocks') {
json.imports.push({
imports: { memo: 'memo' },
path: 'react',
});

json.imports.push({
imports: { isEqual: 'default' },
path: 'react-fast-compare',
});
json.hooks.init = {
code: `
${json.hooks.init?.code || ''}
Expand Down Expand Up @@ -224,6 +231,7 @@ const MEMOIZING_BLOCKS_COMPONENT_PLUGIN = () => ({
data: { code: 'props.blocks', type: 'single' },
renderItem: { code: 'renderItem', type: 'single' },
keyExtractor: { code: 'keyExtractor', type: 'single' },
extraData: { code: 'builderContext', type: 'single' },
removeClippedSubviews: { code: 'true', type: 'single' },
maxToRenderPerBatch: { code: '10', type: 'single' },
windowSize: { code: '5', type: 'single' },
Expand All @@ -240,13 +248,13 @@ const MEMOIZING_BLOCKS_COMPONENT_PLUGIN = () => ({
if (json.name === 'Blocks') {
return code.replace(
'export default Blocks',
'export default memo(Blocks)'
'export default memo(Blocks, isEqual)'
);
}
if (json.name === 'Block') {
return code.replace(
'export default Block',
'export default memo(Block)'
'export default memo(Block, isEqual)'
);
}
return code;
Expand Down
1 change: 1 addition & 0 deletions packages/sdks/output/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"@react-native-async-storage/async-storage": "1.23.1",
"css-to-react-native": "^3.2.0",
"isolated-vm": "^6.0.0",
"react-fast-compare": "^3.2.2",
"react-native-storage": "^1.0.1",
"react-native-video": "^5.1.1"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/sdks/src/functions/evaluate/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function flattenState({
rootSetState: rootSetState
? (subState) => {
target[prop] = subState;
rootSetState(target);
rootSetState({ ...target });
}
: undefined,
});
Expand All @@ -149,8 +149,8 @@ export function flattenState({
}

target[prop] = value;

rootSetState?.(target);
Comment thread
cursor[bot] marked this conversation as resolved.
// Pass a new object reference so React/RN detects the state change
rootSetState?.({ ...target });
return true;
},
});
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7093,6 +7093,7 @@ __metadata:
babel-plugin-module-resolver: ^5.0.0
css-to-react-native: ^3.2.0
isolated-vm: ^6.0.0
react-fast-compare: ^3.2.2
react-native-builder-bob: ^0.21.3
react-native-storage: ^1.0.1
react-native-url-polyfill: ^2.0.0
Expand Down
Loading