This noticeably improves performance in the admin panel, for example
when there are multiple richtext editors on one page (& likely
performance in other areas too, though I mainly tested rich text).
The babel plugin currently only optimizes files with a 'use client'
directive at the top - thus we have to make sure to add use client
wherever possible, even if it's imported by a parent client component.
There's one single component that broke when it was compiled using the
React compiler (it stopped being reactive and failed one of our admin
e2e tests):
150808f608
opting out of it completely fixed that issue
Fixes https://github.com/payloadcms/payload/issues/7366
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { parse, stringify } from 'comment-json'
|
|
import { existsSync, promises } from 'fs'
|
|
import path from 'path'
|
|
import { fileURLToPath } from 'url'
|
|
|
|
import { getNextRootDir } from './helpers/getNextRootDir.js'
|
|
|
|
const { readFile, writeFile, rm } = promises
|
|
const filename = fileURLToPath(import.meta.url)
|
|
const dirname = path.dirname(filename)
|
|
|
|
export const createTestHooks = async (testSuiteName = '_community') => {
|
|
const tsConfigPath = path.resolve(getNextRootDir().rootDir, './tsconfig.json')
|
|
const tsConfigContent = await readFile(tsConfigPath, 'utf8')
|
|
const tsConfig = parse(tsConfigContent)
|
|
|
|
return {
|
|
/**
|
|
* Clear next webpack cache and set '@payload-config' path in tsconfig.json
|
|
*/
|
|
beforeTest: async () => {
|
|
// Delete entire .next cache folder
|
|
const nextCache = path.resolve(getNextRootDir().rootDir, './.next')
|
|
if (existsSync(nextCache)) {
|
|
await rm(nextCache, { recursive: true })
|
|
}
|
|
|
|
// Set '@payload-config' in tsconfig.json
|
|
|
|
// @ts-expect-error
|
|
tsConfig.compilerOptions.paths['@payload-config'] = [
|
|
process.env.PAYLOAD_TEST_PROD === 'true'
|
|
? `./${testSuiteName}/config.ts`
|
|
: `./test/${testSuiteName}/config.ts`,
|
|
]
|
|
await writeFile(tsConfigPath, stringify(tsConfig, null, 2) + '\n')
|
|
|
|
process.env.PAYLOAD_CONFIG_PATH = path.resolve(dirname, testSuiteName, 'config.ts')
|
|
},
|
|
}
|
|
}
|