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
7 changes: 7 additions & 0 deletions .changeset/modern-bags-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lynx-js/react": patch
---

Fix wrong render result when using expression as `key`.

See [lynx-family/lynx-stack#1371](https://github.com/lynx-family/lynx-stack/issues/1371) for more details.
26 changes: 12 additions & 14 deletions packages/react/runtime/__test__/basic.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ describe('setAttribute', () => {
});

describe('dynamic key in snapshot', () => {
it('[FIXME] multiple slots 0', () => {
it('multiple slots 0', () => {
const snapshot = __SNAPSHOT__(
<view>
<view className='foo' key={`foo`}>
Expand All @@ -388,14 +388,11 @@ describe('dynamic key in snapshot', () => {

expect(a.__element_root).toMatchInlineSnapshot(`
<view>
<wrapper>
<view
class="foo"
>
<view />
<view />
</view>
</wrapper>
<view
class="foo"
>
<wrapper />
</view>
</view>
`);
});
Expand All @@ -421,10 +418,7 @@ describe('dynamic key in snapshot', () => {
<view
class="foo"
>
<view>
<wrapper />
<wrapper />
</view>
<wrapper />
</view>
`);
});
Expand Down Expand Up @@ -455,7 +449,11 @@ describe('dynamic key in snapshot', () => {
/>
<wrapper />
</text>
<wrapper />
<view
class="foo"
>
<wrapper />
</view>
</view>
`);
});
Expand Down
118 changes: 59 additions & 59 deletions packages/react/runtime/__test__/preact.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,11 @@ describe('document - background', () => {
);
expect(scratch).toMatchInlineSnapshot(`
<root>
<__Card__:__snapshot_a94a8_test_13
<__Card__:__snapshot_a94a8_test_14
0="world"
>
"Hello"
</__Card__:__snapshot_a94a8_test_13>
</__Card__:__snapshot_a94a8_test_14>
</root>
`);

Expand All @@ -378,14 +378,14 @@ describe('document - background', () => {
);
expect(scratch).toMatchInlineSnapshot(`
<root>
<__Card__:__snapshot_a94a8_test_14>
<__Card__:__snapshot_a94a8_test_15>
"Hello"
</__Card__:__snapshot_a94a8_test_15>
<__Card__:__snapshot_a94a8_test_15>
<__Card__:__snapshot_a94a8_test_16>
"World"
"Hello"
</__Card__:__snapshot_a94a8_test_16>
</__Card__:__snapshot_a94a8_test_14>
<__Card__:__snapshot_a94a8_test_17>
"World"
</__Card__:__snapshot_a94a8_test_17>
</__Card__:__snapshot_a94a8_test_15>
</root>
`);
expect([...backgroundSnapshotInstanceManager.values.keys()])
Expand Down Expand Up @@ -414,17 +414,17 @@ describe('document - background', () => {
render(jsx('Hello!'), scratch);
expect(scratch).toMatchInlineSnapshot(`
<root>
<__Card__:__snapshot_a94a8_test_17>
<__Card__:__snapshot_a94a8_test_18>
"Hello!"
</__Card__:__snapshot_a94a8_test_17>
</__Card__:__snapshot_a94a8_test_18>
</root>
`);
render(jsx('Hello!!'), scratch);
expect(scratch).toMatchInlineSnapshot(`
<root>
<__Card__:__snapshot_a94a8_test_17>
<__Card__:__snapshot_a94a8_test_18>
"Hello!!"
</__Card__:__snapshot_a94a8_test_17>
</__Card__:__snapshot_a94a8_test_18>
</root>
`);
});
Expand Down Expand Up @@ -481,15 +481,15 @@ describe('document - background', () => {
render(jsx('Hello'), scratch);
expect(scratch).toMatchInlineSnapshot(`
<root>
<__Card__:__snapshot_a94a8_test_22
<__Card__:__snapshot_a94a8_test_25
0="Hello"
/>
</root>
`);
render(jsx(null), scratch);
expect(scratch).toMatchInlineSnapshot(`
<root>
<__Card__:__snapshot_a94a8_test_22
<__Card__:__snapshot_a94a8_test_25
0={null}
/>
</root>
Expand All @@ -504,7 +504,7 @@ describe('document - background', () => {
render(jsx(vi.fn()), scratch);
expect(scratch).toMatchInlineSnapshot(`
<root>
<__Card__:__snapshot_a94a8_test_22
<__Card__:__snapshot_a94a8_test_25
0={[MockFunction spy]}
/>
</root>
Expand All @@ -514,7 +514,7 @@ describe('document - background', () => {
render(jsx(vi.fn()), scratch);
expect(scratch).toMatchInlineSnapshot(`
<root>
<__Card__:__snapshot_a94a8_test_22
<__Card__:__snapshot_a94a8_test_25
0={[MockFunction spy]}
/>
</root>
Expand Down Expand Up @@ -599,16 +599,16 @@ describe('document - background', () => {
await Promise.resolve();
expect(scratch).toMatchInlineSnapshot(`
<root>
<__Card__:__snapshot_a94a8_test_24>
<__Card__:__snapshot_a94a8_test_27>
"foo"
</__Card__:__snapshot_a94a8_test_24>
</__Card__:__snapshot_a94a8_test_27>
</root>
`);

await Promise.resolve();
expect(scratch).toMatchInlineSnapshot(`
<root>
<__Card__:__snapshot_a94a8_test_23
<__Card__:__snapshot_a94a8_test_26
0="bar"
/>
</root>
Expand Down Expand Up @@ -647,26 +647,26 @@ describe('document - dual-runtime', () => {
BackgroundSnapshotInstance.prototype.toJSON = backgroundSnapshotInstanceToJSON;
expect(backgroundRoot).toMatchInlineSnapshot(`
<root>
<__Card__:__snapshot_a94a8_test_26>
<__Card__:__snapshot_a94a8_test_27>
<__Card__:__snapshot_a94a8_test_29>
<__Card__:__snapshot_a94a8_test_30>
"W"
</__Card__:__snapshot_a94a8_test_27>
<__Card__:__snapshot_a94a8_test_27>
</__Card__:__snapshot_a94a8_test_30>
<__Card__:__snapshot_a94a8_test_30>
"0"
</__Card__:__snapshot_a94a8_test_27>
<__Card__:__snapshot_a94a8_test_27>
</__Card__:__snapshot_a94a8_test_30>
<__Card__:__snapshot_a94a8_test_30>
"r"
</__Card__:__snapshot_a94a8_test_27>
<__Card__:__snapshot_a94a8_test_27>
</__Card__:__snapshot_a94a8_test_30>
<__Card__:__snapshot_a94a8_test_30>
"l"
</__Card__:__snapshot_a94a8_test_27>
<__Card__:__snapshot_a94a8_test_27>
</__Card__:__snapshot_a94a8_test_30>
<__Card__:__snapshot_a94a8_test_30>
"d"
</__Card__:__snapshot_a94a8_test_27>
<__Card__:__snapshot_a94a8_test_27>
</__Card__:__snapshot_a94a8_test_30>
<__Card__:__snapshot_a94a8_test_30>
"_"
</__Card__:__snapshot_a94a8_test_27>
</__Card__:__snapshot_a94a8_test_26>
</__Card__:__snapshot_a94a8_test_30>
</__Card__:__snapshot_a94a8_test_29>
</root>
`);
delete BackgroundSnapshotInstance.prototype.toJSON;
Expand All @@ -675,35 +675,35 @@ describe('document - dual-runtime', () => {
.toMatchInlineSnapshot(`
[
3,
-68,
-88,
"k",
"0",
3,
-69,
-89,
0,
"0",
0,
"__Card__:__snapshot_a94a8_test_27",
93,
"__Card__:__snapshot_a94a8_test_30",
117,
3,
93,
117,
"k",
"_",
0,
null,
94,
118,
4,
94,
118,
[
"_",
],
1,
93,
94,
117,
118,
undefined,
1,
-65,
93,
-85,
117,
undefined,
]
`);
Expand All @@ -714,33 +714,33 @@ describe('document - dual-runtime', () => {
expect(takeGlobalSnapshotPatch()).toMatchInlineSnapshot(`
[
2,
-65,
-68,
-85,
-88,
2,
-65,
93,
-85,
117,
0,
"__Card__:__snapshot_a94a8_test_27",
95,
"__Card__:__snapshot_a94a8_test_30",
119,
3,
95,
119,
"k",
"1",
0,
null,
96,
120,
3,
96,
120,
0,
"1",
1,
95,
96,
119,
120,
undefined,
1,
-65,
95,
-70,
-85,
119,
-90,
]
`);

Expand Down Expand Up @@ -773,7 +773,7 @@ describe('document - dual-runtime', () => {
BackgroundSnapshotInstance.prototype.toJSON = backgroundSnapshotInstanceToJSON;
expect(backgroundRoot).toMatchInlineSnapshot(`
<root>
<__Card__:__snapshot_a94a8_test_28 />
<__Card__:__snapshot_a94a8_test_31 />
</root>
`);
delete BackgroundSnapshotInstance.prototype.toJSON;
Expand Down
6 changes: 4 additions & 2 deletions packages/react/runtime/__test__/renderToOpcodes.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { createElement, cloneElement } from '../lepus';
import { Suspense } from 'preact/compat';
import { createSuspender } from './createSuspender';
import { __root } from '../src/root';
import { renderMainThread } from '../src/lifecycle/render';

describe('renderToOpcodes', () => {
beforeAll(() => {
Expand Down Expand Up @@ -145,9 +144,11 @@ describe('renderToOpcodes', () => {
});

it('should render with attr', () => {
const random = Math.random();

function App() {
return (
<view key={Math.random()}>
<view random={random}>
<text>Hello World</text>
<raw-text text={'Hello World'.toLowerCase()} />
</view>
Expand All @@ -167,6 +168,7 @@ describe('renderToOpcodes', () => {
2,
"values",
[
${random},
"hello world",
],
1,
Expand Down
Loading
Loading