Skip to content

Commit d0cb4ad

Browse files
dazy-dsmhordynski
authored andcommitted
fix: infinite initialization (#793)
1 parent 336a4d1 commit d0cb4ad

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

packages/ragbits-chat/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# CHANGELOG
22

33
## Unreleased
4+
- Fix bug causing infinite initialization screen (#793)
45
- Fix bug that caused messages to be sent when changing chat settings; simplify and harden history logic (#791)
56
- Add `clear_message` event type allowing to reset whole message (#789)
67
- Add usage component to UI with backend support (#786)

typescript/ui/__tests__/integration/intergation.test.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { ComponentProps } from "react";
1+
import React from "react";
22
import {
33
describe,
44
it,
@@ -37,18 +37,6 @@ import { createHistoryStore } from "../../src/core/stores/HistoryStore/historySt
3737
import { createStore } from "zustand";
3838
import { useHistoryStore } from "../../src/core/stores/HistoryStore/useHistoryStore";
3939
import { HistoryStore } from "../../src/types/history";
40-
import HistoryStoreContextProvider from "../../src/core/stores/HistoryStore/HistoryStoreContextProvider";
41-
42-
vi.mock(
43-
"../../src/core/stores/HistoryStore/HistoryStoreContextProvider.tsx",
44-
() => ({
45-
default: ({
46-
children,
47-
}: ComponentProps<typeof HistoryStoreContextProvider>) => (
48-
<div data-testid="history-store-context-provider">{children}</div>
49-
),
50-
}),
51-
);
5240

5341
vi.mock("../../src/core/stores/HistoryStore/useHistoryStore", () => {
5442
return {
@@ -246,8 +234,13 @@ describe("Integration tests", () => {
246234

247235
render(<WrappedInput />);
248236
const user = userEvent.setup();
249-
const chatOptionsButton =
250-
await screen.findByTestId("open-chat-options");
237+
const chatOptionsButton = await screen.findByTestId(
238+
"open-chat-options",
239+
undefined,
240+
{
241+
timeout: 5000,
242+
},
243+
);
251244
await user.click(chatOptionsButton);
252245
const selectTrigger = await screen.findByLabelText("Language", {
253246
selector: "select",

typescript/ui/src/core/stores/HistoryStore/HistoryStoreContextProvider.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ function initializeStore(shouldStoreHistory: boolean, storeKey: string) {
5656
);
5757
}
5858

59-
return createStore(createHistoryStore);
59+
// Manually set _hasHydrated when we don't use any storage
60+
const store = createStore(createHistoryStore);
61+
store.getState()._internal._setHasHydrated(true);
62+
63+
return store;
6064
}
6165

6266
export default function HistoryStoreContextProvider({
@@ -82,7 +86,7 @@ export default function HistoryStoreContextProvider({
8286
[store],
8387
);
8488

85-
if (!hasHydrated) {
89+
if (shouldStoreHistory && !hasHydrated) {
8690
return <InitializationScreen />;
8791
}
8892

0 commit comments

Comments
 (0)