11import type { Locator , LocatorSelectors , PrettyDOMOptions } from 'vitest/browser'
22import { page , server , utils } from 'vitest/browser'
33import React from 'react'
4- import type { Container } from 'react-dom/client'
4+ import type { Container , RootOptions } from 'react-dom/client'
55import ReactDOMClient from 'react-dom/client'
66
77const { debug, getElementLocatorSelectors } = utils
@@ -64,6 +64,12 @@ export interface ComponentRenderOptions {
6464 container ?: HTMLElement
6565 baseElement ?: HTMLElement
6666 wrapper ?: React . JSXElementConstructor < { children : React . ReactNode } >
67+ /**
68+ * Options passed to React's `createRoot`.
69+ *
70+ * @see {@link https://react.dev/reference/react-dom/client/createRoot API Reference for `createRoot` }
71+ */
72+ createRootOptions ?: RootOptions
6773}
6874
6975export interface RenderOptions extends ComponentRenderOptions { }
@@ -82,7 +88,7 @@ const mountedRootEntries: {
8288 */
8389export async function render (
8490 ui : React . ReactNode ,
85- { container, baseElement, wrapper : WrapperComponent } : ComponentRenderOptions = { } ,
91+ { container, baseElement, wrapper : WrapperComponent , createRootOptions } : RenderOptions = { } ,
8692) : Promise < RenderResult > {
8793 if ( ! baseElement ) {
8894 // default to document.body instead of documentElement to avoid output of potentially-large
@@ -102,7 +108,7 @@ export async function render(
102108 let root : ReactRoot
103109
104110 if ( ! mountedContainers . has ( container ) ) {
105- root = createConcurrentRoot ( container )
111+ root = createConcurrentRoot ( container , createRootOptions )
106112
107113 mountedRootEntries . push ( { container, root } )
108114 // we'll add it to the mounted containers regardless of whether it's actually
@@ -250,8 +256,8 @@ interface ReactRoot {
250256 unmount : ( ) => void
251257}
252258
253- function createConcurrentRoot ( container : HTMLElement ) : ReactRoot {
254- const root = ReactDOMClient . createRoot ( container )
259+ function createConcurrentRoot ( container : HTMLElement , options : RootOptions | undefined ) : ReactRoot {
260+ const root = ReactDOMClient . createRoot ( container , options )
255261
256262 return {
257263 render ( element : React . ReactNode ) {
0 commit comments