I've started working on an example for `tanstack-r...
# react
m
I've started working on an example for
tanstack-react-router-nodejs-test
in kotlin-wrappers. One thing I noticed is that the examples didn't run for me out of the box using
./gradlew tanstack-react-router:jsBrowserDevelopmentRun
I had to run
./gradlew tanstack-react-router:kotlinNodeJsSetup
first before the correct version of node was found. That's probably not going to be obvious to some people. I haven't had to use that in my own react projects, so it's unclear why it was required here.
t
Looks like bug 😞
m
Well, I put together a PR with all of the changes so far, but I've only proposed it against my own fork so far, for a few reasons. First: I wasn't able to get kotlin-wrappers RTL working. I couldn't even get the render method arguments to compile. As a short-term workaround, I pulled the minimally-needed RTL code from the jsmints project and added it as a package. Second: It's unclear to me how to pull some of the dependencies in using the existing version catalogs, so I just added them directly to the build.gradle.kts file for now. Also, I'm not sure if it's that valuable to propose these as separate PRs rather than a set of commits. It appears that github makes it easy to review the files specific to a commit independently of the total PR. For example, you can start at the first commit here and click the "prev/next" controls at the top to see what each commit changed: https://github.com/mkienenb/kotlin-wrappers/pull/1/changes/c934373b444a1752241a8b598f2757deaa7fa4b9
Now that I have a working example, I might try to convert it to the kotlinwrappers RTL one more time when I get a chance
It's not as nice an API and missing
act {}
, but I think I got the KW RTL mostly working using
render()
. Unfortunately. fireEvent() RTL gets runtime errors. I also tried KW testingLibraryUserEvent but that dies with an error at startup. The API there is pretty bad, forcing the end-user to pass in js("undefined") to function calls, but it's a start.
Copy code
Exception during run: Error: Package subpath './dist/esm/setup/index' is not defined by "exports"
  in .../kotlin-wrappers/examples/build/js/node_modules/@testing-library/user-event/package.json
  imported from .../kotlin-wrappers/examples/build/js/packages/tanstack-react-router-nodejs-test-test/kotlin/tanstack-react-router-nodejs-test-test/example/RouterTest.mjs
t
cc @Sergei Grishchenko
s
> I wasn't able to get kotlin-wrappers RTL working. I couldn't even get the render method arguments to compile. > ... > Now that I have a working example, I might try to convert it to the kotlinwrappers RTL one more time when I get a chance So, you still have some problems with render method arguments? May I find problematic code in you PRs or in your fork? May I ask you to create some issues with reports about problems with render method not to forget about these problems? > It's not as nice an API May you provide code examples? I know there might be some flaws in current API because it seem you are the first user that tries it 🙂. If you have some ideas how we can test API in KW, please, share. What do you think, adding an example with some RTL test to KW examples folder is good approach? > missing
act {}
As far as I understand
act
is reexported from React as is, recently we also moves
act
to
react
package in KW, please, try to use
act
from that place, if it does not work for you, please, describe what is wrong, we will try to fix the issue > fireEvent() RTL gets runtime errors To reproduce it I may use you fork, right? >
Copy code
Exception during run: Error: Package subpath './dist/esm/setup/index' is not defined by "exports"
hm, interesting, as far as I can see from NPM
Copy code
"exports": {
    ".": {
      "types": "./dist/types/index.d.ts",
      "require": "./dist/cjs/index.js",
      "default": "./dist/esm/index.js"
    },
    "./dist/cjs/*.js": {
      "types": "./dist/types/*.d.ts",
      "import": "./dist/esm/*.js",
      "default": "./dist/cjs/*.js"
    },
    "./dist/esm/*.js": {
      "types": "./dist/types/*.d.ts",
      "default": "./dist/esm/*.js",
      "require": "./dist/cjs/*.js"
    }
  },
so
./dist/esm/setup/index
should be matched by
./dist/esm/*.js
pattern, maybe K/JS do not generate
.js
extension in the import statement and that is the problem... we need to investigate it, thank you for the report
m
Hi @Sergei Grishchenko, I'll try to provide examples as time permits, but since we use the kotlin wrappers from jsmints to provide RTL and user-event library (UE) in our project, I will have to do this in my spare time. It would be nice to have this same functionality in the kotlin-wrappers project and to use it instead. > If you have some ideas how we can test API in KW, please, share. What do you think, adding an example with some RTL test to KW examples folder is good approach? Yes, this is what I have done. This is the example using jsmints wrappers. It would be a good idea to see how jsmints has provided the API since those of us using RTL and UE in kotlin/js up to this point are using the jsmints API. branch: https://github.com/mkienenb/kotlin-wrappers/tree/mlk/tanstack-react-router-nodejs-test-example PR: https://github.com/mkienenb/kotlin-wrappers/pull/1/changes This is the example modified to use kotlin-wrapper wrappers for RTL and UE. This is the branch with Package subpath './dist/esm/setup/index' is not defined by "exports" error. branch: https://github.com/mkienenb/kotlin-wrappers/tree/mlk/tanstack-react-router-nodejs-test-example__kotlinwrappers_RTL_UE PR: https://github.com/mkienenb/kotlin-wrappers/pull/2/changes I've taken another look at using fireEvent, and found the right syntax and imports to use it. So here's a working example using RTL without UE. branch: https://github.com/mkienenb/kotlin-wrappers/tree/mlk/tanstack-react-router-nodejs-test-example__kotlinwrappers_RTL_fireEvent PR: https://github.com/mkienenb/kotlin-wrappers/pull/3/changes >> It's not as nice an API > May you provide code examples? I use jsmint differently, with act {} instead of render() and UE instead of fireEvent, but here's some differences that I noticed in this example project. - CONS: * Screen calls require explicit typecasting of returned values - kotlin-wrappers:
val indexContainer : web.dom.Element = screen.findByTestId(DataTestId.INDEX_CONTAINER)
- jsmint:
val indexContainer = screen.findByTestId(DataTestId.INDEX_CONTAINER)
* Screen calls require explicit typecasting of returned values - kotlin-wrappers:
val indexContainer : web.dom.Element = screen.findByTestId(DataTestId.INDEX_CONTAINER)
- jsmint:
val indexContainer = screen.findByTestId(DataTestId.INDEX_CONTAINER)
* fireEvent needs a convenience wrapper - kotlin-wrappers RTL:
fireEvent[EventType.click]?.invoke(topicsLink, js("undefined"))
- jsmint:
fireEvent.click(topicsLink)
*
fireEvent(options=)
does not default to
js("undefined")
- kotlin-wrappers RTL:
fireEvent[EventType.click]?.invoke(topicsLink, js("undefined"))
- expected:
fireEvent[EventType.click]?.invoke(topicsLink)
* adding kotlinWrappers.testingLibraryReact dependency requires adding npm("@testing-library/react", "VERSION") dependency. - kotlin-wrappers RTL: jsTestImplementation(kotlinWrappers.testingLibraryReact) jsTestImplementation(npm("@testing-library/react", "latest")) - jsmint (from our production project): implementation(project.dependencies.enforcedPlatform(libs.jsmints.bom)) implementation(libs.jsmints.react.testing.library) implementation(libs.jsmints.user.event.testing.library.js) *
userEvent.setup
does not default to
js("undefined")
- kotlin-wrappers UE:
val user = userEvent.setup(JS_UNDEFINED)
- jsmint:
val user = UserEvent.setup()
*
user.click(options=)
does not default to
js("undefined")
- kotlin-wrappers UE:
user.click(topicsLink, JS_UNDEFINED).await()
- jsmint:
user.click(topicsLink)
*
user.click()
does not automatically await() the returned promise - kotlin-wrappers UE:
user.click(topicsLink, JS_UNDEFINED).await()
- jsmint:
user.click(topicsLink)
* jsmint's act {} also awaits() before returning - PROS: * jsmint doesn't provide cleanup(). - kotlin-wrappers RTL:
cleanup()
- jsmint:
act { root.unmount() }
container.remove()
* I hadn't used RTL render() before, but it's nice not to have to set up the document and container, which I have to do with act {}. Maybe jsmint also works this way. I need to do more research.
s
> Screen calls require explicit typecasting of returned values Original API from TS library allows to pass type of DOM element that you expect as query result, I guess it might be useful if you want to examine some properties that are specific to some HTML elements (e.g. for input). If I hardcode element type instead of generic you will have to typecast or
unsafeCast
results of querying if you want to get some specific props I guess you can use something like this
Copy code
val indexContainer = screen.findByTestId<Element>(DataTestId.INDEX_CONTAINER)
(Also I noticed this point is mentioned twice, maybe you wanted to report something else by forget to replace the copied point? I don't want to lose feedback 🙂) > fireEvent needs a convenience wrapper Will it be actual if primary method of event dispatching is UE? >
fireEvent(options=)
does not default to
js("undefined")
Got it, unfortunately Kotlin does not support optional params in function types, I will think about how to adapt this API. BTW you can use
undefined
constant without js block. > * adding kotlinWrappers.testingLibraryReact dependency requires adding npm("@testing-library/react", "VERSION") dependency misconfig, I pushed the fix >
userEvent.setup
does not default to
js("undefined")
Yes, you are right, I will fix it. It know issue. >
user.click(options=)
does not default to
js("undefined")
The same as previous >
user.click()
does not automatically await() the returned promise The same as previous, UE are on really on early stage of conversion, most promise APIs will be wrapped to suspends
> jsmint's act {} also awaits() before returning As far as I can see current declaration of act is suspendable, and should await result
also I notices you use some
JS_UNDEFINED
constant, why you do not use just undefined? Is it because of WASM related staff of something like this?
m
Original API from TS library allows to pass type of DOM element that you expect as query result, I guess it might be useful if you want to examine some properties that are specific to some HTML elements (e.g. for input). If I hardcode element type instead of generic you will have to typecast or unsafeCast results of querying if you want to get some specific props
The only use case we've had for the query result is to either click it, type text into it, or examine attributes of the html element. All of those require that the type be an HTMLElement. Having it return a generic adds boilerplate to every statement. This is how jsmints exposes it:
Copy code
import org.w3c.dom.HTMLElement

interface ByTestId {
    fun getByTestId(text: String): HTMLElement
    suspend fun findByTestId(text: String): HTMLElement
    fun queryByTestId(text: String): HTMLElement?
    fun getAllByTestId(text: String): Array<HTMLElement>
    fun queryAllByTestId(text: String): Array<HTMLElement>
    suspend fun findAllByTestId(text: String): Array<HTMLElement>
}
Will [fireEvent] be actual if primary method of event dispatching is UE?
We never use fireEvent and always use UE, but that's what was available for the example. jsmints made it easier to use fireEvent.
I notices you use some JS_UNDEFINED constant, why you do not use just undefined?
I didn't know it existed :) We don't do much with raw javascript from kotlin. Sounds like it won't matter as the final code won't need to specify undefined.
generic query result
Also, without an explicit type, the code doesn't compile:
val indexContainer = screen.findByTestId(DataTestId.INDEX_CONTAINER)
Cannot infer type for type parameter 'T'. Specify it explicitly.
s
This is how jsmints exposes it:
Yea, I checked that declarations, and unfortunately I am suspicious about type narrowing to
HTMLElement
, I guess
Element
as upper bound of generic allows you also querying SVG elements, I understand that SVG is not so popular but I would not limit users with to narrow solution also, because KW is common library.
t
DataTestId
can be inteface with type parameter, which will contain right type
s
Sorry I was wrong, upper bound of generic is
HTMLElement
DataTestId
can be inteface with type parameter, which will contain right type
sorry, I dont think that is good solution, because there are other queries, like
findAllByLabelText
and it would be uncommon and very local fix just for one type of query.
Also, without an explicit type, the code doesn't compile:
Yea, this is exactly because right now
<T : web.html.HTMLElement/>
is declared, an there is not point in code to get exact type for
T
but you can write something like
Copy code
val indexContainer = screen.findByTestId<HTMLElement>(DataTestId.INDEX_CONTAINER)
And code should compile
m
Yes, I know I can do both of these:
val indexContainer = screen.findByTestId<HTMLElement>(DataTestId.INDEX_CONTAINER)
and
val indexContainer : HTMLElement = screen.findByTestId(DataTestId.INDEX_CONTAINER)
It seems unnecessary to always specify the same generic type and never a different one. jsmints non-generic functions are nicer. That's not a show-stopper, but it's an API inconvenience. We could replace all of the query statements with our own extension functions to hide this, but that'd likely be more inconvenient. Who's the target audience and what do they need for an api? So far, all of us kotlin RTL users are using jsmints API and no one has asked for a different signature. Again, it wouldn't prevent me from switching from jsmints to KW, but it's not ideal. Also, after more investigation, it looks like I should have been using render() instead of act {} all along. We'll need to make that change in our production project.
The one other piece we frequently use is within(). In a jsmints example, it'd look like this:
Copy code
val componentTopicLink = within(screen.findByTestId<HTMLElement>(DataTestId.TOPICS_CONTAINER)).findByTestId<HTMLElement>(DataTestId.TOPIC_LINK_COMPONENTS)
I'm not sure what that is intended to look like in KW. The above code generates:
Copy code
Cannot infer type for type parameter 'R'. Specify it explicitly.
Cannot infer type for type parameter 'T'. Specify it explicitly.
<html>Unresolved reference. None of the following candidates is applicable because of a receiver type mismatch:<br/>fun <T, R> DeepRecursiveFunction<T, R>.invoke(value: T): R
Unresolved reference 'findByTestId'.
s
> Who's the target audience and what do they need for an api? @turansky Correct me if I am wrong, but I guess that we are looking for our target audience, and I would like to extend it as match as possible. It is not about evolution (even if it is also important thing), but it is about being opinionated. If we wrap some library, and make decision, that limits some API of this library, and we automatically became authors of our new variation of that library, and we will have to describe all limitations we did, but it is bunch of work actually (docs, examples, etc.). Without modifications we can just refer to original docs and say: "Just copy JS examples, fix compile errors, and job is done". Tragedy is that more common and abstract API leads to more inconvenience. If you want to have more convenient API, you will have to sacrifice some flexibility. E.g. C lang gives you full control of memory allocations, but is inconvenient, Java manages memory for you, but you don't have control anymore. About current generic situation, I see 2 points here • Kotlin has type projection with
<*>
syntax, but it works not everywhere, it would be nice to write
screen.findByTestId<*>(DataTestId.INDEX_CONTAINER)
and fail to upper bound of generic, but unfortunately it is not possible now, but I see it as good compromise between flexibility and convenience • Actually Testing library does not provide any guaranties that returned item will have exact type that was passed in
<T>
param, and it is not good because it leads to unsound code. Maybe it is good reason to remove generics, but for now I don't know what is better: give more generic and unsound API or give more safe but narrow API.
>
Copy code
val componentTopicLink = within
Yea, I see, now
within
has type
Any
because of TS metaprogramming, I will take a look and try to improve type declarations for it.
m
Once there's working within() support, I can create a branch of our production project and migrate it over to KW. There's 200-300 tests, so it should be a good test case if there's anything else that needs attention.
t
@Mike Kienenberger our common goal - cool Kotlin API. In case of
findByTestId
it can be better for sure. For start - we can remove generics (it's what we do for some browser declarations). Kotlin Wrappers meta issue will be best place for non-comfortable API in RTL 😉 cc @Sergei Grishchenko
m
@turansky, I think I'm ready to make a PR against KW providing a KW RTL and KW tanstack react router example. Do you still want me to do separate PRs for each commit? Is there any particular naming convention you'd prefer? I'm guessing create an issue first before making the PRs? I created a new branch and local PR first and cleaned it up, so there won't be any leftover refererences to jsmints or KW UE. https://github.com/mkienenb/kotlin-wrappers/pull/4
s
I totally forget to warn you, if you use
render()
, you still have to run
cleanup()
after each test, maybe we will provide some API to reduce these boilerplate in the future.
m
I totally forget to warn you, if you use
render()
, you still have to run
cleanup()
after each test, maybe we will provide some API to reduce these boilerplate in the future.
Thanks. Yes, I knew that 🙂 and it's in the example test. Using cleanup is so much better than what we were having to do before, with having to remove container and unmount root. I copied the cleanup.kt file into our production project to take advantage of it since jsmints didn't provide it. All of our production testing code inherits from a superclass and hides all of that boilerplate.
👌 1
s
> Screen calls require explicit typecasting of returned values After discussion with @turansky we decided to remove generics in
Screen
API, because they are unsound. > fireEvent needs a convenience wrapper > ... >
fireEvent(options=)
does not default to
js("undefined")
I decided not to do anything with this API for now, because as far as I understand, primary approach for event dispatching is UE. >
Copy code
val componentTopicLink = within(screen.findByTestId<HTMLElement>(DataTestId.TOPICS_CONTAINER)).findByTestId<HTMLElement>(DataTestId.TOPIC_LINK_COMPONENTS)
I tried to improve types for
within
helper. I hope problem should be fixed. >
userEvent.setup
does not default to
js("undefined")
> ... >
user.click(options=)
does not default to
js("undefined")
> ... >
user.click()
does not automatically await() the returned promise I tried to rework and improve UE API, with latest changes these problems should gone, if not - please, reach us. >
Copy code
Exception during run: Error: Package subpath './dist/esm/setup/index' is not defined by "exports"
I found the problem with
@JsModule
in generated declarations. I fixed generation and added some primitive tests to check that entities from UE are available in runtime.
Release is in deployment process. Changes should be available soon. If I missed some point or feedback - please, mention it again. If some fix does not work for you, please, notify us, we will try to improve API if it possible.
m
@Sergei Grishchenko, it's all working for me with the mlk/tanstack-react-router-RTL-UE-nodejs-test-example branch after rebasing on KW/master. • within() works • non-generic screen queries work • user.click() works • no longer need to import npm user-event testing library I've removed all of my other branches and I'll be using this one to eventually submit a KW example PR.
👍 2
@Sergei Grishchenko, with the 2026.3.8 kotlin-wrappers release, I was able to switch our production project from jsmints to KW RTL and UE. The one glitch is that jsmints sets
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
but KW does not. I had to add this to build.gradle.kts
Copy code
compilations.named("test") {
            packageJson { customField("mocha", mapOf("require" to arrayOf(
                            "../../../../tools/mocha-support/set-react-act-env.js",
                            [...]
            )))}
        }
and
Copy code
// tools/mocha-support/set-react-act-env.js
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
I'm guessing there's a better way to do it, but that's what I came up with.
👍 1
s
with KW you can execute
Copy code
globalThis["IS_REACT_ACT_ENVIRONMENT"] = true
in
@BeforeTest
method, it might help
m
It looks like jsmints does it like this for RTL: jsTest >> Main.kt
Copy code
package com.zegreatrob.wrapper.testinglibrary.react

fun main() {
    js("global.IS_REACT_ACT_ENVIRONMENT=true")
}
And like this for UE: jsTest >> Main.kt
Copy code
package com.zegreatrob.wrapper.testinglibrary.userevent

fun main() {
    js("global.IS_REACT_ACT_ENVIRONMENT=true")
    js("global.IS_JSDOM=true")
}
s
Interesting, I didn't know that you can use
main
function as global setup for tests.
BTW,
globalThis["IS_REACT_ACT_ENVIRONMENT"] = true
is Kotlin code, KW provides global val for
globalThis
m
I think when I was debugging Kotest/coroutines issues, I ran across something that said all main() methods in jsTest will get executed.
BTW,
globalThis["IS_REACT_ACT_ENVIRONMENT"] = true
is Kotlin code, KW provides global val for
globalThis
Yes, testing that now.
Yes, adding
Copy code
globalThis["IS_REACT_ACT_ENVIRONMENT"] = true
            globalThis["IS_JSDOM"] = true
in the before test calls does work, but it does mean that the end-developer has to remember to do so for each test. Not a big deal in our environment since all of our react tests inherit from a single superclass. But if we go this route, it'd mean we'd need to add some docs to KW RTL and KW UE
t
Do you use
runTest
from Coroutines Test?
m
No, we do not. coroutines-test is fine for unit testing where you expect to micromanage the coroutines, but almost all of our tests are integration tests with no knowledge of what coroutines are used behind the scenes. We use the real coroutines default dispatcher.
The example I am working on shows doing it both ways.
t
It means, that you have custom
runTest
?
m
No, for our prod project, we use kotest, not kotlin.test, so it works out of the box. For the example project, I used
Copy code
// Use dependency injection to inject this test CoroutineScope into your production code instead of MainScope
    object JsTestScope : CoroutineScope {
        override val coroutineContext =
            SupervisorJob() + Dispatchers.Default
    }

    @Test
    fun shouldClickTopicsLinkAndNavigateToTopicsPage(): Promise<Unit> = JsTestScope.promise {
    }
I probably should expand that example to provide DI support since real tests would require it.
We decided to go ahead and switch our prod project over to KW and stop using jsmints.
👍 1
Thanks for making this available!
@Sergei Grishchenko I'm thinking that we should move the IS_REACT_ACT_ENVIRONMENT setting into the RTL wrappers.
Copy code
globalThis["IS_REACT_ACT_ENVIRONMENT"] = true
This is the expected place it would be set from according to the documentation, rather than requiring end-users to do it. https://react.dev/reference/react/act#error-the-current-testing-environment-is-not-configured-to-support-act
Note
In testing frameworks like React Testing Library,
IS_REACT_ACT_ENVIRONMENT
is already set for you.
I looked into filing a bug report about jsNodeTest and
NODE_ENV=test
. I don't think we can consider this a bug so much as two competing design philosophies. Node.js says don't do it. Jest and Vite do it by default. Maybe I should update the README for the testing example to include this?
Copy code
* `@tanstack/react-router` requires `NODE_ENV=test` to run in a node/jsdom environment. By default, no `NODE_ENV` mode
  is set.
    - Work-around: Change `build.gradle.kts` to set `NODE_ENV=test` when running jsNodeTest
    - The requirement to set `NODE_ENV=test` is not a bug in the jsNodeTask.
      * Requiring the use of `NODE_ENV=test` is considered an anti-pattern by the node.js project.
        - <https://nodejs.org/en/learn/getting-started/nodejs-the-difference-between-development-and-production#why-is-node_env-considered-an-antipattern>
      * Setting `NODE_ENV=test` is considered standard practice by the vite project.
        - <https://vitest.dev/guide/migration.html?utm_source=chatgpt.com#envs>
t
Node.js says don't do it.
In that case it's custom plugin/project responsibility
m
I agree. I was just wondering if I should update the README to make it clear.
t
Looks like we miss
jsdom
Gradle plugin 😉
Which will do all this dark magic 😉
👍 1
s
I thought that
act
from testing library is tiny wrapper over
act
from React, now I see that it is not true. I will remove
act
in
react
package and move it's declaration to testing library. @turansky does it work for you?
thank you color 1
👌 1
👌 1
I pushed the fix, @Mike Kienenberger after release
act
with correct
IS_REACT_ACT_ENVIRONMENT
should be available from
testing.library.react
package
m
I looked at your commit, but it doesn't seem to involve
IS_REACT_ACT_ENVIRONMENT.
This seems to be the code that sets IS_REACT_ACT_ENVIRONMENT by calling https://github.com/testing-library/react-testing-library/blob/main/src/index.js#L32 which calls https://github.com/testing-library/react-testing-library/blob/main/src/act-compat.js#L28 But it's not completely compatible with kotlin since it tries to instrument the beforeTest and afterTest code of testing libraries. This is probably why jsmints unconditionally set IS_REACT_ACT_ENVIRONMENT.
t
This is probably why jsmints unconditionally set IS_REACT_ACT_ENVIRONMENT.
In custom
runTest
?
m
No, jsmint set it in a main() method, so it'd be triggered any time jsmint was loaded.
But that doesn't look like an exact match for the original behavior. I guess this goes back to:
Looks like we miss jsdom Gradle plugin 😉
Which will do all this dark magic 😉
t
I did it in custom
runTest
😉
Which is synchronous with RTL. Set before, remove after
m
The issue with that approach is that it's only going to work for people using coroutines-test. It's not a huge deal for the end-user to set it in the before/after tests for whatever framework is being used. It's just another thing that's not obvious that needs to be done. I can add it to the existing example project.
t
But you don't use
act
in example, right?
m
Not currently. In our real project, the only place we directly use act{} is in router.navigate(path), so it would fit well in the example. I wonder if methods like render() implicitly call act internally and need that value, though?
t
They wrap some calls (
dispatchEvent
for example)
m
Some research shows that RTL render() also calls act. So setting IS_REACT_ACT_ENVIRONMENT is likely important for any react test. https://github.com/testing-library/react-testing-library/blob/main/src/pure.js#L167
s
Actually there are 2 `act`s • from React -> does not setup anything and complains that
IS_REACT_ACT_ENVIRONMENT
is not set • from Testing Library -> wraps React's
act
+ sets up
IS_REACT_ACT_ENVIRONMENT
before and after its calling In the code you provided
act
is imported from local file
Copy code
import act, ... from './act-compat'
So I hope that is not bare React's
act
, it is wrapped one. So I hope if you use RTL
render
you are in safe and you should not receive any warnings about env. But if you have some problems anyway, please share some test snippet, I can try to debug it.
In Wrappers I didn't do any manual work to make
act
safe, I just exported exiting safe version from RTL
m
Copy code
versionCatalogs {
         create("kotlinWrappers") {
-            val wrappersVersion = "2026.3.13"
+            val wrappersVersion = "2026.3.15"
@Sergei Grishchenko, did you remove react.act? I don't think that's a good idea. If the end user is not using RTL, they likely need react.act. The end-user is going to have to be knowledgeable enough to determine which import they use. https://react.dev/reference/react/act
You might end up breaking existing projects which are using react.act
t
We need use cases and users. For now
react.act
is problem for RTL users unfortunately 😞
m
Actually, I found the regression because we were using react.act by accident 🙂 it was all working fine, but then stopped compiling. However, for us, the right thing was to switch to rtl.act.
I had switched from RTL act to react act back when Sergei first said to do so, and never switched it back
Also, kotlin wrappers still ships kotlin-react-dom-test-utils-js which requires react.act. EDIT: actually, that's not true. It uses react.dom.test.act This is what was originally recommend by KW, and I started with that before finding a better solution. For example. https://github.com/mkienenb/web-app-react-kotlin-js-gradle/blob/mlk/iban-validator-react-tdd-kata/src/jsTest/kotlin/WelcomeComponentTest.kt
actually, that's not true. It uses react.dom.test.act
Too many "act"s. I wonder what DOES use react.act now -- I was sure it was react-dom-test-utils
Maybe act is only used by other act implementations
👍 1
t
> Maybe act is only used by other act implementations It's what we expect in common 😉
s
The situation actually is complicated. What I observe: • originally
act
was declared in
react-dom/test-utils
• approximately around React 19
act
was moved to
react
package and other helpers from
react-dom/test-utils
were removed • here and there React docs mention RTL, so I assume the it is de facto standard • I don't remember how it worked before, but now
act
from
react
requires
IS_REACT_ACT_ENVIRONMENT
to work correctly, I tried to investigate what RTL does to provide correct setup for
IS_REACT_ACT_ENVIRONMENT
and I found this code, as you can see, this code is not trivial and I don't expect that every end user of React should write this. After all these facts I consider
act
from
react
package as low-level API for testing library authors and RTL one of such library that seems de facto standard. So original
act
from
react
may be useful only if some Kotlin enthusiast want to write alternative library for React testing, For now I see it as very low probable scenario, that is why I don't see much sense in declaration of
act
from
react
package. If I am missing something, please, share you thoughts.
thank you color 1
👍 2