conform icon indicating copy to clipboard operation
conform copied to clipboard

Remix single fetch: returning submission.reply() with action results in type never.

Open coji opened this issue 9 months ago • 5 comments

Describe the bug and the expected behavior

https://github.com/remix-run/remix/issues/9374

Conform version

v1.1.3

Steps to Reproduce the Bug or Issue

https://stackblitz.com/~/github.com/coji/conform-on-remix-single-fetch

What browsers are you seeing the problem on?

Chrome

Screenshots or Videos

CleanShot 2024-05-04 at 23 12 53@2x

Additional context

I have also raised it as a remix issue. I think it may be a type definition problem on the remix side. https://github.com/remix-run/remix/issues/9374

coji avatar May 04 '24 14:05 coji

I've received feedback from several users about an issue with SubmissionResult's prop Result<string, unknown>. The unknown type is problematic because it introduces uncertainty about serializability by turbo-stream, which could lead to runtime errors. https://github.com/remix-run/remix/issues/9374#issuecomment-2096739839

To address this, it's recommended to replace unknown with a more specific type that turbo-stream can reliably serialize. This will improve type safety and prevent potential issues. However, I'm not quite sure how to best implement this change while maintaining compatibility and avoiding any unintended consequences. I would greatly appreciate your guidance on the most appropriate way to refactor the code to resolve this problem.

coji avatar May 11 '24 13:05 coji

I've updated to remix v2.9.2 and the type error is gone, However, the newly introduced defineAction / defineLoader still seems to cause type errors due to Result<string, unknown>.

https://github.com/remix-run/remix/issues/9374#issuecomment-2106128088

coji avatar May 12 '24 05:05 coji

I'm encountering the type error with defineAction as well. I worked around it for now by omitting the initialValue prop since that's the one with the Record<string, unknown> type. Would definitely love an official fix though 🙂

skycoop avatar Jun 27 '24 20:06 skycoop

@coji FYI this specific error is caused by a typo. You're using actionData.lastResult while your action returns lastRusult

timvandam avatar Jul 13 '24 06:07 timvandam

Has anyone managed to get conform submission.reply() working with the new remix singlefetch and the new unstable_data to return raw data accompanied with a status code or custom response headers. I am getting

Type 'SubmissionResult<string[]> | DataWithResponseInit<SubmissionResult<string[]>> | undefined' is not assignable to type 'SubmissionResult<string[]> | null | undefined'. Type 'DataWithResponseInit<SubmissionResult<string[]>>' has no properties in common with type 'SubmissionResult<string[]>'.ts(2322)

when trying to assign lastResult to the useForm hook?

JasonColeyNZ avatar Aug 08 '24 01:08 JasonColeyNZ