-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store-sync): wait for idle after each chunk of logs in a block (#…
…2254) Co-authored-by: Kevin Ingersoll <[email protected]> Co-authored-by: yonada <[email protected]>
- Loading branch information
1 parent
5ab67e3
commit f0a343b
Showing
3 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@latticexyz/store-sync": minor | ||
--- | ||
|
||
`createStoreSync` now [waits for idle](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback) between each chunk of logs in a block to allow for downstream render cycles to trigger. This means that hydrating logs from an indexer will no longer block until hydration completes, but rather allow for `onProgress` callbacks to trigger. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { rpcHttpUrl } from "./setup/constants"; | ||
import { deployContracts } from "./setup"; | ||
import { createAsyncErrorHandler } from "./asyncErrors"; | ||
import { createWorld, getComponentValueStrict } from "@latticexyz/recs"; | ||
import { singletonEntity, syncToRecs } from "@latticexyz/store-sync/recs"; | ||
import mudConfig from "../contracts/mud.config"; | ||
import { transportObserver } from "@latticexyz/common"; | ||
import { ClientConfig, createPublicClient, http, isHex } from "viem"; | ||
import { getNetworkConfig } from "../client-vanilla/src/mud/getNetworkConfig"; | ||
|
||
describe("syncToRecs", () => { | ||
const asyncErrorHandler = createAsyncErrorHandler(); | ||
|
||
it("has the correct sync progress percentage", async () => { | ||
asyncErrorHandler.resetErrors(); | ||
|
||
const { stdout } = await deployContracts(rpcHttpUrl); | ||
|
||
const [, worldAddress] = stdout.match(/worldAddress: '(0x[0-9a-f]+)'/i) ?? []; | ||
if (!isHex(worldAddress)) { | ||
throw new Error("world address not found in output, did the deploy fail?"); | ||
} | ||
|
||
const networkConfig = await getNetworkConfig(); | ||
const clientOptions = { | ||
chain: networkConfig.chain, | ||
transport: transportObserver(http(rpcHttpUrl ?? undefined)), | ||
pollingInterval: 1000, | ||
} as const satisfies ClientConfig; | ||
|
||
const publicClient = createPublicClient(clientOptions); | ||
|
||
const world = createWorld(); | ||
|
||
const { components } = await syncToRecs({ | ||
world, | ||
config: mudConfig, | ||
address: worldAddress, | ||
publicClient, | ||
}); | ||
|
||
expect(getComponentValueStrict(components.SyncProgress, singletonEntity).percentage).toMatchInlineSnapshot(` | ||
100 | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters