Skip to content

Commit

Permalink
feat(cli): react compiler lint only setting (#10761)
Browse files Browse the repository at this point in the history
This PR adds to the TOML configuration for the experimental react
compiler. It adds a `lintOnly` option which when set to true will enable
linting rules but not include the compiler during code compilation.
  • Loading branch information
Josh-Walker-GM committed Jun 9, 2024
1 parent 7e065cd commit 73241a0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changesets/10761.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- feat(cli): react compiler lint only setting (#10761) by @Josh-Walker-GM

You can now add `lintOnly = true` within your `[experimental.reactCompiler]` TOML settings to enable the react compiler linting rules without the compiler itself enabled during code compilation. See [here](https://community.redwoodjs.com/t/react-compiler-setup-experimental/7128) for more details.
10 changes: 7 additions & 3 deletions packages/babel-config/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ export const getWebSideBabelPlugins = (
// Need the project config to know if trusted graphql documents is being used and decide to use
// the gql tag import or the trusted document gql function generated by code gen client preset
const config = getConfig()
const reactCompilerEnabled =
config.experimental?.reactCompiler?.enabled ?? false

// The compiler config has both an enabled and lintOnly setting so we have to ensure
// the user wants to do more than simply lint before enabling the plugin
const useReactCompiler =
config.experimental?.reactCompiler?.enabled &&
config.experimental?.reactCompiler?.lintOnly === false

const useTrustedDocumentsGqlTag = config.graphql.trustedDocuments

Expand All @@ -44,7 +48,7 @@ export const getWebSideBabelPlugins = (
const commonPlugins = forVite ? [] : getCommonPlugins()
const plugins = [
// It is important that this plugin run first, as noted here: https://react.dev/learn/react-compiler
reactCompilerEnabled && [
useReactCompiler && [
'babel-plugin-react-compiler',
{
// No specific config at this time...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const handler = async ({ force, verbose }) => {
writeFile(
redwoodTomlPath,
configContent.concat(
'\n[experimental.reactCompiler]\n enabled = true\n',
'\n[experimental.reactCompiler]\n enabled = true\n lintOnly = false\n',
),
{
overwriteExisting: true, // redwood.toml always exists
Expand Down
1 change: 1 addition & 0 deletions packages/project-config/src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('getConfig', () => {
},
"reactCompiler": {
"enabled": false,
"lintOnly": false,
},
"realtime": {
"enabled": false,
Expand Down
2 changes: 2 additions & 0 deletions packages/project-config/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export interface Config {
}
reactCompiler: {
enabled: boolean
lintOnly: boolean
}
}
}
Expand Down Expand Up @@ -207,6 +208,7 @@ const DEFAULT_CONFIG: Config = {
},
reactCompiler: {
enabled: false,
lintOnly: false,
},
},
}
Expand Down

0 comments on commit 73241a0

Please sign in to comment.