Files
payload/test/eslint.config.js
Jacob Fletcher ac1e3cf69e feat(ui): form state queues (#11579)
Implements a form state task queue. This will prevent onChange handlers
within the form component from processing unnecessarily often, sometimes
long after the user has stopped making changes. This leads to a
potentially huge number of network requests if those changes were made
slower than the debounce rate. This is especially noticeable on slow
networks.

Does so through a new `useQueue` hook. This hook maintains a stack of
events that need processing but only processes the final event to
arrive. Every time a new event is pushed to the stack, the currently
running process is aborted (if any), and that event becomes the next in
the queue. This results in a shocking reduction in the time it takes
between final change to form state and the final network response, from
~1.5 minutes to ~3 seconds (depending on the scenario, see below).

This likely fixes a number of existing open issues. I will link those
issues here once they are identified and verifiably fixed.

Before:

I'm typing slowly here to ensure my changes aren't debounce by the form.
There are a total of 60 characters typed, triggering 58 network requests
and taking around 1.5 minutes to complete after the final change was
made.


https://github.com/user-attachments/assets/49ba0790-a8f8-4390-8421-87453ff8b650

After:

Here there are a total of 69 characters typed, triggering 11 network
requests and taking only about 3 seconds to complete after the final
change was made.


https://github.com/user-attachments/assets/447f8303-0957-41bd-bb2d-9e1151ed9ec3
2025-03-10 21:25:14 -04:00

90 lines
2.8 KiB
JavaScript

import { defaultESLintIgnores, rootEslintConfig, rootParserOptions } from '../eslint.config.js'
import payloadPlugin from '@payloadcms/eslint-plugin'
import playwright from 'eslint-plugin-playwright'
/** @typedef {import('eslint').Linter.Config} Config */
/** @type {Config[]} */
export const testEslintConfig = [
...rootEslintConfig,
{
ignores: [...defaultESLintIgnores, '**/payload-types.ts', 'jest.setup.js'],
},
{
languageOptions: {
parserOptions: {
...rootParserOptions,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
'payload/no-relative-monorepo-imports': 'error',
},
},
{
files: ['**/*.ts'],
rules: {
'payload/no-jsx-import-statements': 'warn',
'payload/no-relative-monorepo-imports': 'error',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-use-before-define': 'off',
// turn the @typescript-eslint/unbound-method rule off *only* for test files. See https://typescript-eslint.io/rules/unbound-method/#when-not-to-use-it
'@typescript-eslint/unbound-method': 'off',
'no-console': 'off',
'perfectionist/sort-objects': 'off',
},
},
{
files: ['**/*.int.spec.ts', '**/int.spec.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'jest/prefer-strict-equal': 'off',
},
},
{
...playwright.configs['flat/recommended'],
files: ['**/*.e2e.spec.ts', '**/e2e.spec.ts', 'helpers.ts'],
},
{
files: ['**/*.e2e.spec.ts', '**/e2e.spec.ts', 'helpers.ts'],
rules: {
'payload/no-relative-monorepo-imports': 'error',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'jest/consistent-test-it': 'off',
'jest/expect-expect': 'off',
'jest/no-test-callback': 'off',
'jest/prefer-strict-equal': 'off',
'jest/require-top-level-describe': 'off',
'jest-dom/prefer-to-have-attribute': 'off',
'playwright/prefer-web-first-assertions': 'error',
'payload/no-flaky-assertions': 'warn',
'payload/no-wait-function': 'warn',
// Enable the no-non-retryable-assertions rule ONLY for hunting for flakes
// 'payload/no-non-retryable-assertions': 'error',
'playwright/expect-expect': [
'error',
{
assertFunctionNames: [
'assertToastErrors',
'saveDocAndAssert',
'runFilterOptionsTest',
'assertNetworkRequests',
],
},
],
},
},
{
files: ['*.e2e.ts'],
rules: {
'payload/no-relative-monorepo-imports': 'error',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'jest/expect-expect': 'off',
},
},
]
export default testEslintConfig