|
5 | 5 | */ |
6 | 6 | import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; |
7 | 7 |
|
8 | | -import { Component, createRef, useState } from '../../src/index'; |
| 8 | +import { Component, createRef, root, useState } from '../../src/index'; |
| 9 | +import { delayedLifecycleEvents } from '../../src/lifecycle/event/delayLifecycleEvents'; |
9 | 10 | import { replaceCommitHook } from '../../src/lifecycle/patch/commit'; |
10 | 11 | import { injectUpdateMainThread } from '../../src/lifecycle/patch/updateMainThread'; |
11 | 12 | import { renderBackground as render } from '../../src/lifecycle/render'; |
@@ -1650,4 +1651,105 @@ describe('element ref in list', () => { |
1650 | 1651 | `); |
1651 | 1652 | } |
1652 | 1653 | }); |
| 1654 | + |
| 1655 | + it('when __FIRST_SCREEN_SYNC_TIMING__ is jsReady', async function() { |
| 1656 | + globalThis.__FIRST_SCREEN_SYNC_TIMING__ = 'jsReady'; |
| 1657 | + const refs = [createRef(), createRef(), createRef()]; |
| 1658 | + const signs = [0, 0, 0]; |
| 1659 | + |
| 1660 | + class ListItem extends Component { |
| 1661 | + render() { |
| 1662 | + return <view ref={this.props._ref}></view>; |
| 1663 | + } |
| 1664 | + } |
| 1665 | + |
| 1666 | + class Comp extends Component { |
| 1667 | + render() { |
| 1668 | + return ( |
| 1669 | + <list> |
| 1670 | + {[0, 1, 2].map((index) => { |
| 1671 | + return ( |
| 1672 | + <list-item item-key={index}> |
| 1673 | + <ListItem _ref={refs[index]}></ListItem> |
| 1674 | + </list-item> |
| 1675 | + ); |
| 1676 | + })} |
| 1677 | + </list> |
| 1678 | + ); |
| 1679 | + } |
| 1680 | + } |
| 1681 | + |
| 1682 | + // main thread render |
| 1683 | + { |
| 1684 | + __root.__jsx = <Comp />; |
| 1685 | + renderPage(); |
| 1686 | + } |
| 1687 | + |
| 1688 | + // list render item 1 & 2 |
| 1689 | + { |
| 1690 | + signs[0] = elementTree.triggerComponentAtIndex(__root.childNodes[0].__elements[0], 0); |
| 1691 | + expect(globalThis.__OnLifecycleEvent).toHaveBeenCalledTimes(1); |
| 1692 | + |
| 1693 | + globalEnvManager.switchToBackground(); |
| 1694 | + lynxCoreInject.tt.OnLifecycleEvent(...globalThis.__OnLifecycleEvent.mock.calls[0]); |
| 1695 | + globalThis.__OnLifecycleEvent.mockClear(); |
| 1696 | + expect(delayedLifecycleEvents).toMatchInlineSnapshot(` |
| 1697 | + [ |
| 1698 | + [ |
| 1699 | + "rLynxRef", |
| 1700 | + { |
| 1701 | + "commitTaskId": undefined, |
| 1702 | + "refPatch": "{"-4:0:":62}", |
| 1703 | + }, |
| 1704 | + ], |
| 1705 | + ] |
| 1706 | + `); |
| 1707 | + } |
| 1708 | + |
| 1709 | + // background render |
| 1710 | + { |
| 1711 | + globalEnvManager.switchToBackground(); |
| 1712 | + root.render(<Comp />, __root); |
| 1713 | + expect(lynx.getNativeApp().callLepusMethod).toHaveBeenCalledTimes(1); |
| 1714 | + expect(lynx.getNativeApp().callLepusMethod.mock.calls[0]).toMatchInlineSnapshot(` |
| 1715 | + [ |
| 1716 | + "rLynxJSReady", |
| 1717 | + {}, |
| 1718 | + ] |
| 1719 | + `); |
| 1720 | + globalEnvManager.switchToMainThread(); |
| 1721 | + const rLynxJSReady = lynx.getNativeApp().callLepusMethod.mock.calls[0]; |
| 1722 | + globalThis[rLynxJSReady[0]](rLynxJSReady[1]); |
| 1723 | + lynx.getNativeApp().callLepusMethod.mockClear(); |
| 1724 | + expect(globalThis.__OnLifecycleEvent).toHaveBeenCalledTimes(1); |
| 1725 | + expect(globalThis.__OnLifecycleEvent.mock.calls).toMatchInlineSnapshot(` |
| 1726 | + [ |
| 1727 | + [ |
| 1728 | + [ |
| 1729 | + "rLynxFirstScreen", |
| 1730 | + { |
| 1731 | + "jsReadyEventIdSwap": {}, |
| 1732 | + "refPatch": "{}", |
| 1733 | + "root": "{"id":-1,"type":"root","children":[{"id":-2,"type":"__Card__:__snapshot_a94a8_test_24","children":[{"id":-3,"type":"__Card__:__snapshot_a94a8_test_25","values":[{"item-key":0}],"children":[{"id":-4,"type":"__Card__:__snapshot_a94a8_test_23","values":["-4:0:"]}]},{"id":-5,"type":"__Card__:__snapshot_a94a8_test_25","values":[{"item-key":1}],"children":[{"id":-6,"type":"__Card__:__snapshot_a94a8_test_23","values":["-6:0:"]}]},{"id":-7,"type":"__Card__:__snapshot_a94a8_test_25","values":[{"item-key":2}],"children":[{"id":-8,"type":"__Card__:__snapshot_a94a8_test_23","values":["-8:0:"]}]}]}]}", |
| 1734 | + }, |
| 1735 | + ], |
| 1736 | + ], |
| 1737 | + ] |
| 1738 | + `); |
| 1739 | + } |
| 1740 | + |
| 1741 | + { |
| 1742 | + globalEnvManager.switchToBackground(); |
| 1743 | + lynxCoreInject.tt.OnLifecycleEvent(...globalThis.__OnLifecycleEvent.mock.calls[0]); |
| 1744 | + globalThis.__OnLifecycleEvent.mockClear(); |
| 1745 | + |
| 1746 | + expect(refs[0].current).toMatchInlineSnapshot(` |
| 1747 | + { |
| 1748 | + "selectUniqueID": [Function], |
| 1749 | + "uid": 62, |
| 1750 | + } |
| 1751 | + `); |
| 1752 | + } |
| 1753 | + globalThis.__FIRST_SCREEN_SYNC_TIMING__ = 'immediately'; |
| 1754 | + }); |
1653 | 1755 | }); |
0 commit comments