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.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ test.describe('Large Reactive State', () => {
// Initial state
await expect(page.getByText('0', { exact: true })).toBeVisible();

// log page contents
console.log(await page.content());
Copy link

Choose a reason for hiding this comment

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

Debug console.log accidentally left in test file

Low Severity

A console.log(await page.content()) statement was added to the maintains reactivity with large state test. This dumps the entire page HTML to the test output on every run, which is clearly leftover debugging code unrelated to the PR's purpose of adding deep memo comparison.

Fix in Cursor Fix in Web


// Increment multiple times
for (let i = 1; i <= 5; i++) {
await page.getByText('Increment Number').click();
Expand Down
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);
// 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