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
2 changes: 2 additions & 0 deletions packages/react-sdk/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ export function BucketProvider({
void clientRef.current.stop();
}

setFeaturesLoading(true);

const client = newBucketClient({
...config,
user,
Expand Down
48 changes: 48 additions & 0 deletions packages/react-sdk/test/usage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,54 @@ describe("<BucketProvider />", () => {
expect(initialize).toHaveBeenCalledOnce();
expect(BucketClient.prototype.stop).not.toHaveBeenCalledOnce();
});

test("resets loading state when context changes", async () => {
const { queryByTestId, rerender } = render(
getProvider({
loadingComponent: <span data-testid="loading">Loading...</span>,
}),
);

// Loading component should be visible initially
expect(queryByTestId("loading")).not.toBeNull();

// Wait for initial loading to complete
await waitFor(() => {
expect(queryByTestId("loading")).toBeNull();
});

// Change user context
rerender(
getProvider({
loadingComponent: <span data-testid="loading">Loading...</span>,
user: { ...user, id: "new-user-id" },
}),
);

// Loading should appear again
expect(queryByTestId("loading")).not.toBeNull();

// Wait for loading to complete again
await waitFor(() => {
expect(queryByTestId("loading")).toBeNull();
});

// Change company context
rerender(
getProvider({
loadingComponent: <span data-testid="loading">Loading...</span>,
company: { ...company, id: "new-company-id" },
}),
);

// Loading should appear again
expect(queryByTestId("loading")).not.toBeNull();

// Wait for loading to complete again
await waitFor(() => {
expect(queryByTestId("loading")).toBeNull();
});
});
});

describe("useFeature", () => {
Expand Down