Skip to content

Commit 7a21bc5

Browse files
authored
v3.1 release (#200)
Co-authored-by: Alex Nicholson <alex.n@clove.kitchen>
1 parent eb4d136 commit 7a21bc5

5 files changed

Lines changed: 85 additions & 5 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: V3.1.0 has been released
3+
description: Release notes for version 3.1.0
4+
date: 2025-10-07
5+
---
6+
7+
Version 3.1.0 for React Dialog Async has been released 🎉
8+
9+
## What's new?
10+
11+
This release contains bug fixes for v3, special thanks to rovo89.
12+
13+
- Fixes `DialogProvider` not being marked with `"use client"` after migration to rolldown
14+
- `useDialogLazy()` now correctly loads the default export of a module by default
15+
---
16+
17+
Feedback or ideas? We'd love to hear them! Open an issue over on [GitHub](https://github.com/a16n-dev/react-dialog-async/issues).

packages/react-dialog-async/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-dialog-async",
33
"description": "Ergonomic & performant dialog hooks for React & React Native",
44
"type": "module",
5-
"version": "3.0.0",
5+
"version": "3.1.0",
66
"sideEffects": false,
77
"main": "./dist/index.cjs",
88
"module": "./dist/index.js",

packages/react-dialog-async/src/DialogProvider/DialogProvider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import {
24
useContext,
35
useEffect,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { type PropsWithChildren } from 'react';
2+
import { expect, test, vi } from 'vitest';
3+
import { renderHook } from '@testing-library/react';
4+
import { DialogProvider } from '../DialogProvider/DialogProvider.js';
5+
import { DialogOutlet } from '../DialogOutlet/DialogOutlet.js';
6+
import { useDialogLazy } from './useDialogLazy.js';
7+
8+
const TestWrapper = ({ children }: PropsWithChildren) => (
9+
<DialogProvider>
10+
{children}
11+
<DialogOutlet />
12+
</DialogProvider>
13+
);
14+
15+
const TestDialog = () => <div>Hello World!</div>;
16+
17+
test('Calling preload() calls the loader function', () => {
18+
const loaderFn = vi.fn(async () => TestDialog);
19+
20+
const { result } = renderHook(() => useDialogLazy(loaderFn), {
21+
wrapper: TestWrapper,
22+
});
23+
24+
result.current.preload();
25+
26+
expect(loaderFn).toHaveBeenCalledTimes(1);
27+
});
28+
29+
test('Passing a dynamic import in the loader function automatically loads the default export', async () => {
30+
const { result } = renderHook(
31+
() =>
32+
useDialogLazy(async () => {
33+
return await new Promise<{ default: typeof TestDialog }>((resolve) =>
34+
setTimeout(() => resolve({ default: TestDialog }), 50),
35+
);
36+
}),
37+
{
38+
wrapper: TestWrapper,
39+
},
40+
);
41+
42+
void result.current.open();
43+
44+
await new Promise((resolve) => setTimeout(resolve, 100));
45+
46+
const dialog = document.querySelector('div');
47+
48+
expect(dialog).toBeTruthy();
49+
expect(dialog?.textContent).toBe('Hello World!');
50+
});

packages/react-dialog-async/src/useDialogLazy/useDialogLazy.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { DialogActionsContext } from '../context/DialogActionsContext.js';
55
import type { useDialogLazyReturn } from './types.js';
66

77
export function useDialogLazy<D, R, DE extends D | undefined>(
8-
componentLoader: () => Promise<AsyncDialogComponent<D, R>>,
8+
componentLoader: () => Promise<
9+
AsyncDialogComponent<D, R> | { default: AsyncDialogComponent<D, R> }
10+
>,
911
options?: useDialogOptions<D, DE>,
1012
): useDialogLazyReturn<D, R, DE> {
1113
const id = useId();
@@ -25,7 +27,10 @@ export function useDialogLazy<D, R, DE extends D | undefined>(
2527
// Call the lazy loader function with a callback to load the component
2628
void ctx.lazyLoaderFn(async () => {
2729
if (!componentRef.current) {
28-
componentRef.current = await componentLoader();
30+
const loaderResult = await componentLoader();
31+
32+
componentRef.current =
33+
'default' in loaderResult ? loaderResult.default : loaderResult;
2934
}
3035
});
3136
}
@@ -42,7 +47,10 @@ export function useDialogLazy<D, R, DE extends D | undefined>(
4247
const open = useCallback(
4348
async (data?: D): Promise<R | undefined> => {
4449
if (!componentRef.current) {
45-
componentRef.current = await componentLoader();
50+
const loaderResult = await componentLoader();
51+
52+
componentRef.current =
53+
'default' in loaderResult ? loaderResult.default : loaderResult;
4654
}
4755

4856
return ctx.show(
@@ -66,7 +74,10 @@ export function useDialogLazy<D, R, DE extends D | undefined>(
6674

6775
const preload = async () => {
6876
if (!componentRef.current) {
69-
componentRef.current = await componentLoader();
77+
const loaderResult = await componentLoader();
78+
79+
componentRef.current =
80+
'default' in loaderResult ? loaderResult.default : loaderResult;
7081
}
7182
};
7283

0 commit comments

Comments
 (0)