chore(ui): add ability to compile using react compiler (#6483)

This does not enable the react compiler by default
This commit is contained in:
Alessio Gravili
2024-05-27 22:54:36 -04:00
committed by GitHub
parent eff5129a5f
commit 96181d91a6
56 changed files with 1485 additions and 145 deletions

View File

@@ -16,7 +16,7 @@
"development": false,
"useBuiltins": true
}
}
},
"experimental": {
"plugins": [
[

View File

@@ -0,0 +1,2 @@
> 1%
not dead

View File

@@ -16,7 +16,7 @@
"development": false,
"useBuiltins": true
}
}
},
"experimental": {
"plugins": [
[

View File

@@ -0,0 +1,55 @@
const fs = require('fs')
const ReactCompilerConfig = {
sources: (filename) => {
if(!filename.endsWith('.tsx') && !filename.endsWith('.jsx')) {
return false
}
// read file and check if 'use client' is at top. if not, return false
// if it is, return true
const file = fs.readFileSync(filename, 'utf8')
if(file.includes("'use client'")) {
//console.log("Compiling: " + filename)
return true
}
console.log("Skipping: " + filename)
return false
},
//runtimeModule: "react"
}
module.exports = function (api) {
api.cache(false);
return {
plugins: [
['babel-plugin-react-compiler', ReactCompilerConfig], // must run first!
[
'babel-plugin-transform-remove-imports',
{
test: '\\.(scss|css)$',
},
],
],
presets: [
[
'@babel/preset-env',
{
modules: false,
useBuiltIns: 'usage',
corejs: '3.22',
},
],
[
'@babel/preset-react',
{
throwIfNamespace: false,
runtime: 'automatic',
},
],
'@babel/preset-typescript',
],
}
}

View File

@@ -81,8 +81,10 @@
],
"scripts": {
"build": "pnpm copyfiles && pnpm build:swc && pnpm build:types",
"build:babel": "babel src --out-dir dist --source-maps --extensions .ts,.js,.tsx,.jsx,.cjs,.mjs",
"build:reactcompiler": "pnpm copyfiles && pnpm build:babel && pnpm build:types",
"build:remove-artifact": "rm dist/prod/index.js",
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
"build:swc": "swc ./src -d dist --config-file .swcrc",
"build:types": "tsc --emitDeclarationOnly --outDir dist",
"build:webpack": "webpack --config webpack.config.js",
"clean": "rimraf {dist,*.tsbuildinfo}",
@@ -116,6 +118,11 @@
"uuid": "9.0.1"
},
"devDependencies": {
"@babel/cli": "^7.24.5",
"@babel/core": "^7.24.5",
"@babel/preset-env": "^7.24.5",
"@babel/preset-react": "^7.24.1",
"@babel/preset-typescript": "^7.24.1",
"@payloadcms/eslint-config": "workspace:*",
"@types/body-scroll-lock": "^3.1.0",
"@types/qs": "6.9.7",
@@ -123,6 +130,8 @@
"@types/react-datepicker": "6.2.0",
"@types/react-dom": "npm:types-react-dom@19.0.0-beta.2",
"@types/uuid": "8.3.4",
"babel-plugin-react-compiler": "0.0.0-experimental-592953e-20240517",
"babel-plugin-transform-remove-imports": "^1.7.1",
"css-loader": "^6.10.0",
"css-minimizer-webpack-plugin": "^6.0.0",
"mini-css-extract-plugin": "1.6.2",

View File

@@ -1,3 +1,4 @@
'use client'
import React from 'react'
import { Chevron } from '../../icons/Chevron/index.js'

View File

@@ -1,3 +1,4 @@
'use client'
import LinkImport from 'next/link.js' // TODO: abstract this out to support all routers
import type { MouseEvent } from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import type { ElementType } from 'react'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import EditorImport from '@monaco-editor/react'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import React, { Suspense, lazy } from 'react'
import type { Props } from './types.js'

View File

@@ -1,3 +1,4 @@
'use client'
import type { ReactDatePickerProps } from 'react-datepicker'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import React, { Suspense, lazy } from 'react'
import type { Props } from './types.js'

View File

@@ -1,3 +1,4 @@
'use client'
import type { UseDraggableArguments } from '@dnd-kit/core'
import React, { Fragment } from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import type { DragEndEvent } from '@dnd-kit/core'
import {

View File

@@ -1,3 +1,4 @@
'use client'
import type { UseDraggableArguments } from '@dnd-kit/core'
import { useSortable } from '@dnd-kit/sortable'

View File

@@ -1,3 +1,4 @@
'use client'
import { useId } from 'react'
import { useEditDepth } from '../../providers/EditDepth/index.js'

View File

@@ -1,3 +1,4 @@
'use client'
import React from 'react'
import { useTranslation } from '../../providers/Translation/index.js'

View File

@@ -1,3 +1,4 @@
'use client'
import type { I18nClient } from '@payloadcms/translations'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import type { FieldWithPath } from 'payload/types'
import React, { Fragment, type JSX, useState } from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import { formatFilesize } from 'payload/utilities'
import React, { useState } from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import { isImage } from 'payload/utilities'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import React from 'react'
import './index.scss'

View File

@@ -1,3 +1,4 @@
'use client'
import { getTranslation } from '@payloadcms/translations'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import { getTranslation } from '@payloadcms/translations'
import { useRouter } from 'next/navigation.js'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import React from 'react'
import { Chevron } from '../../../icons/Chevron/index.js'

View File

@@ -1,3 +1,4 @@
'use client'
import React from 'react'
export type PageProps = {

View File

@@ -1,3 +1,4 @@
'use client'
import React from 'react'
export const Separator: React.FC = () => <span className="paginator__separator">&mdash;</span>

View File

@@ -1,3 +1,4 @@
'use client'
import React from 'react'
import './index.scss'

View File

@@ -1,3 +1,4 @@
'use client'
import type {
Data,
FileSize,

View File

@@ -1,3 +1,4 @@
'use client'
import type { ClearIndicatorProps } from 'react-select'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import type { ControlProps } from 'react-select'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import type { DropdownIndicatorProps } from 'react-select'
import { Chevron } from '@payloadcms/ui/icons/Chevron'

View File

@@ -1,3 +1,4 @@
'use client'
import type { MultiValueProps } from 'react-select'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import type { MultiValueProps } from 'react-select'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import type { MultiValueRemoveProps } from 'react-select'
import React, { type JSX } from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import type { SingleValueProps } from 'react-select'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import type { ValueContainerProps } from 'react-select'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import React from 'react'
export type RenderCustomComponentProps = {

View File

@@ -1,3 +1,4 @@
'use client'
import { getTranslation } from '@payloadcms/translations'
// TODO: abstract the `next/navigation` dependency out from this component
import { usePathname, useRouter } from 'next/navigation.js'

View File

@@ -1,3 +1,4 @@
'use client'
import type { OptionObject } from 'payload/types'
import type { SanitizedCollectionConfig } from 'payload/types'

View File

@@ -1,3 +1,4 @@
'use client'
import type { DefaultCellComponentProps } from 'payload/types'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import { type CellComponentProps, type SanitizedCollectionConfig } from 'payload/types'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import type { FieldMap, MappedField } from '../../providers/ComponentMap/buildComponentMap/types.js'
// 1. Skips fields that are hidden, disabled, or presentational-only (i.e. `ui` fields)

View File

@@ -1,3 +1,4 @@
'use client'
import type { SanitizedCollectionConfig, TypeWithID } from 'payload/types'
import React from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import React from 'react'
import type { Props } from './types.js'

View File

@@ -1,3 +1,4 @@
'use client'
import React from 'react'
import type { Props } from './types.js'

View File

@@ -1,3 +1,4 @@
'use client'
/* eslint-disable @typescript-eslint/no-floating-promises */
import type { PaginatedDocs } from 'payload/database'

View File

@@ -1,3 +1,4 @@
'use client'
import type { Option, OptionObject } from 'payload/types'
import { getTranslation } from '@payloadcms/translations'

View File

@@ -1,3 +1,4 @@
'use client'
import React from 'react'
import type { Props } from './types.js'

View File

@@ -1,3 +1,4 @@
'use client'
import React, { useEffect, useState } from 'react'
import type { FieldCondition } from '../types.js'

View File

@@ -1,3 +1,4 @@
'use client'
import { getTranslation } from '@payloadcms/translations'
import React, { useEffect, useState } from 'react'

View File

@@ -1,3 +1,4 @@
'use client'
import type { Column } from '../Table/index.js'
import fieldTypes from './field-types.js'

View File

@@ -1,3 +1,4 @@
'use client'
import type { FieldPermissions } from 'payload/auth'
import type { ArrayField, Row } from 'payload/types'

View File

@@ -1,3 +1,4 @@
'use client'
import React from 'react'
import { Search } from '../../../../graphics/Search/index.js'

View File

@@ -1,3 +1,4 @@
'use client'
import React from 'react'
import { useField } from '../../../forms/useField/index.js'

1508
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff