Skip to content

Commit

Permalink
SSR support fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MosheZemah committed Oct 6, 2024
1 parent 737c66e commit 66ed3ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,7 @@ describe("Dropdown renders correctly", () => {
const component = new DropdownDriver().withOpenMenuOnClick().withOpenMenuOnFocus().withVirtualizedOptions();

// Wrap your focusInput call in act to ensure all updates are processed
await act(async () => {
// Wait for the useEffect to finish
await new Promise(resolve => setTimeout(resolve, 100));
});
component.focusInput();
await component.renderWithEffects();

expect(component.snapshot).toMatchSnapshot();
});
Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/components/Dropdown/__tests__/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ export default class DropdownDriver {
render() {
cleanup();
this.renderResult = render(<Dropdown {...this.props} />);
return this.renderResult;
}

async renderWithEffects() {
cleanup();
await act(async () => {
this.renderResult = render(<Dropdown {...this.props} />);

// If there's asynchronous logic in useEffect, we can await it here
await new Promise(resolve => setTimeout(resolve, 100)); // Adjust timeout based on the async logic
});
return this.renderResult;
}

ensureRendered() {
Expand Down

0 comments on commit 66ed3ad

Please sign in to comment.