Skip to content

Commit 708bcb2

Browse files
authored
followup from prior releases (#3813)
* chore: add short contributor guide * revert: "perf(FieldArray): add shouldComponentUpdate to cut down on unnecessary renders (#3784)" Unfortunately this change introduced some unwanted behavior in deeply-composed JSX that relied on state other than that provided by Formik. This reverts commit 22e236e. * chore: fix playwright and update workflows * chore: try a different fix * chore: ignore webkit for now * chore: add changeset for revert
1 parent 2b194c2 commit 708bcb2

File tree

7 files changed

+31
-69
lines changed

7 files changed

+31
-69
lines changed

.changeset/rare-cars-compete.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'formik': patch
3+
---
4+
5+
Revert `FieldArray` "shouldComponentUpdate" performance optimization. As it turns out, it's a common use case to have JSX controlled via non-Formik state/props inside of `FieldArray`, so it's not safe to cancel re-renders here.

.github/workflows/playwright.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,11 @@ jobs:
1212
- uses: actions/checkout@v3
1313
- uses: actions/setup-node@v3
1414
with:
15+
cache: yarn
1516
node-version: 18
1617

17-
- name: Get yarn cache directory path
18-
id: yarn-cache-dir-path
19-
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
20-
21-
- uses: actions/cache@v3
22-
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
23-
with:
24-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
25-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
26-
restore-keys: |
27-
${{ runner.os }}-yarn-
28-
2918
- name: Install dependencies
30-
run: yarn
19+
run: yarn install --frozen-lockfile
3120

3221
- name: Get installed Playwright version
3322
id: playwright-version

.github/workflows/release.yml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,10 @@ jobs:
1313
with:
1414
fetch-depth: 0
1515

16-
- name: Use Node.js 18.x
17-
uses: actions/setup-node@v3
16+
- uses: actions/setup-node@v3
1817
with:
19-
node-version: 18.x
20-
21-
- name: Get yarn cache directory path
22-
id: yarn-cache-dir-path
23-
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
24-
25-
- uses: actions/cache@v3
26-
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
27-
with:
28-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
29-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
30-
restore-keys: |
31-
${{ runner.os }}-yarn-
18+
cache: yarn
19+
node-version: 18
3220

3321
- name: Install Dependencies
3422
run: yarn install

.github/workflows/test.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,14 @@ jobs:
2020
- name: Use Node.js ${{ matrix.node }}
2121
uses: actions/setup-node@v3
2222
with:
23+
cache: yarn
2324
node-version: ${{ matrix.node }}
2425

25-
- name: Get yarn cache directory path
26-
id: yarn-cache-dir-path
27-
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
28-
29-
- uses: actions/cache@v3
30-
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
31-
with:
32-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
33-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
34-
restore-keys: |
35-
${{ runner.os }}-yarn-
36-
3726
- name: Install deps, build, and test
3827
run: |
3928
node --version
4029
npm --version
41-
yarn --version
30+
yarn --version
4231
yarn install --frozen-lockfile
4332
yarn test --coverage
4433
env:

packages/formik/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
- Jared Palmer [@jaredpalmer](https://twitter.com/jaredpalmer)
2626
- Ian White [@eonwhite](https://twitter.com/eonwhite)
2727

28+
## Contributing
29+
30+
This monorepo uses `yarn`, so to start you'll need the package manager installed.
31+
32+
To run E2E tests you'll also need Playwright set up, which can be done locally via `npx playwright install`. Afterward, run `yarn start:app` and in a separate tab run `yarn e2e:ui` to boot up the test runner.
33+
34+
When you're done with your changes, we use [changesets](https://github.com/changesets/changesets) to manage release notes. Run `yarn changeset` to autogenerate notes to be appended to your pull request.
35+
36+
Thank you!
37+
2838
## Contributors
2939

3040
Formik is made with <3 thanks to these wonderful people

packages/formik/src/FieldArray.tsx

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export type FieldArrayConfig = {
2727
name: string;
2828
/** Should field array validate the form AFTER array updates/changes? */
2929
validateOnChange?: boolean;
30-
/** Override FieldArray's default shouldComponentUpdate */
31-
shouldUpdate?: (nextProps: {}, props: {}) => boolean;
3230
} & SharedRenderProps<FieldArrayRenderProps>;
3331
export interface ArrayHelpers<T extends any[] = any[]> {
3432
/** Imperatively add a value to the end of an array */
@@ -155,26 +153,6 @@ class FieldArrayInner<Values = {}> extends React.Component<
155153
this.pop = this.pop.bind(this) as any;
156154
}
157155

158-
shouldComponentUpdate(props: any) {
159-
if (this.props.shouldUpdate) {
160-
return this.props.shouldUpdate(props, this.props);
161-
} else if (
162-
props.name !== this.props.name ||
163-
getIn(props.formik.values, this.props.name) !==
164-
getIn(this.props.formik.values, this.props.name) ||
165-
getIn(props.formik.errors, this.props.name) !==
166-
getIn(this.props.formik.errors, this.props.name) ||
167-
getIn(props.formik.touched, this.props.name) !==
168-
getIn(this.props.formik.touched, this.props.name) ||
169-
Object.keys(this.props).length !== Object.keys(props).length ||
170-
props.formik.isSubmitting !== this.props.formik.isSubmitting
171-
) {
172-
return true;
173-
} else {
174-
return false;
175-
}
176-
}
177-
178156
componentDidUpdate(
179157
prevProps: FieldArrayConfig & { formik: FormikContextType<Values> }
180158
) {

playwright.config.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig, devices } from '@playwright/test';
1+
import { PlaywrightTestProject, defineConfig, devices } from '@playwright/test';
22

33
/**
44
* Read environment variables from file.
@@ -42,10 +42,13 @@ export default defineConfig({
4242
use: { ...devices['Desktop Firefox'] },
4343
},
4444

45-
{
46-
name: 'webkit',
47-
use: { ...devices['Desktop Safari'] },
48-
},
45+
// this one does not seem to be functional in github actions
46+
!process.env.CI
47+
? {
48+
name: 'webkit',
49+
use: { ...devices['Desktop Safari'] },
50+
}
51+
: null,
4952

5053
/* Test against mobile viewports. */
5154
// {
@@ -66,7 +69,7 @@ export default defineConfig({
6669
// name: 'Google Chrome',
6770
// use: { ..devices['Desktop Chrome'], channel: 'chrome' },
6871
// },
69-
],
72+
].filter(Boolean) as PlaywrightTestProject[],
7073

7174
/* Run your local dev server before starting the tests */
7275
webServer: {

0 commit comments

Comments
 (0)