Skip to content

Commit

Permalink
RSC: Use react/experimental types (#9196)
Browse files Browse the repository at this point in the history
Using these types both for RW the framework and RW apps
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/experimental.d.ts

This gives us proper types for `<form action...` in RW apps
  • Loading branch information
Tobbe committed Sep 18, 2023
1 parent a7bab85 commit e2c14eb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
22 changes: 22 additions & 0 deletions packages/cli/src/commands/experimental/setupRscHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from 'path'
import execa from 'execa'
import { Listr } from 'listr2'

import { prettify } from '@redwoodjs/cli-helpers'
import { getConfig, getConfigPath } from '@redwoodjs/project-config'
import { errorTelemetry } from '@redwoodjs/telemetry'

Expand Down Expand Up @@ -185,6 +186,27 @@ export const handler = async ({ force, verbose }) => {
})
},
},
{
title: 'Add React experimental types',
task: async () => {
const tsconfigPath = path.join(rwPaths.web.base, 'tsconfig.json')
const tsconfig = JSON.parse(fs.readFileSync(tsconfigPath, 'utf-8'))

if (tsconfig.compilerOptions.types.includes('react/experimental')) {
return
}

tsconfig.compilerOptions.types.push('react/experimental')

writeFile(
tsconfigPath,
prettify('tsconfig.json', JSON.stringify(tsconfig, null, 2)),
{
overwriteExisting: true,
}
)
},
},
{
title: 'Patch vite',
task: async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-var */
/// <reference types="react/canary" />
/// <reference types="react/experimental" />
import type { HelmetServerState } from 'react-helmet-async'

declare global {
Expand Down
1 change: 0 additions & 1 deletion packages/vite/src/fully-react/assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export function Assets() {
// Do we also need special code for SSR?
// if (isClient) return <ClientAssets />

// @ts-expect-error Need experimental types here for this to work
return <ServerAssets />
}

Expand Down

0 comments on commit e2c14eb

Please sign in to comment.