Skip to content

Commit

Permalink
Merge branch 'main' into create-factory
Browse files Browse the repository at this point in the history
  • Loading branch information
kassens authored Dec 12, 2023
2 parents 658d24d + 0cdfef1 commit bf9d240
Show file tree
Hide file tree
Showing 45 changed files with 482 additions and 169 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ jobs:
- run:
command: |
mkdir -p ./build/__test_utils__
node ./scripts/print-warnings/print-warnings.js > build/WARNINGS
node ./scripts/print-warnings/print-warnings.js --js > build/__test_utils__/ReactAllWarnings.js
node ./scripts/print-warnings/print-warnings.js > build/__test_utils__/ReactAllWarnings.js
- persist_to_workspace:
root: .
paths:
Expand Down
19 changes: 9 additions & 10 deletions .github/workflows/commit_artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,24 @@ jobs:
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
- name: Move relevant files for React in www into compiled
run: |
mkdir -p ./compiled
mkdir -p ./compiled/facebook-www
mkdir -p ./compiled/babel-plugin-react-refresh
# Copy the facebook-www folder into compiled
# Move the facebook-www folder into compiled
mkdir ./compiled
mv build/facebook-www ./compiled
# Copy WARNINGS to facebook-www
mv build/WARNINGS ./compiled/facebook-www/WARNINGS
# Move ReactAllWarnings.js to facebook-www
mkdir ./compiled/facebook-www/__test_utils__
mv build/__test_utils__/ReactAllWarnings.js ./compiled/facebook-www/__test_utils__/ReactAllWarnings.js
# Copy eslint-plugin-react-hooks into facebook-www
# Move eslint-plugin-react-hooks into facebook-www
mv build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
./compiled/facebook-www/eslint-plugin-react-hooks.js
# Copy unstable_server-external-runtime.js into facebook-www
# Move unstable_server-external-runtime.js into facebook-www
mv build/oss-stable/react-dom/unstable_server-external-runtime.js \
./compiled/facebook-www/unstable_server-external-runtime.js
# Copy react-refresh-babel.development.js into babel-plugin-react-refresh
# Move react-refresh-babel.development.js into babel-plugin-react-refresh
mkdir ./compiled/babel-plugin-react-refresh
mv build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js \
./compiled/babel-plugin-react-refresh/index.js
Expand Down
4 changes: 2 additions & 2 deletions fixtures/dom/src/__tests__/nested-act-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('unmocked scheduler', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
DOMAct = require('react-dom/test-utils').act;
DOMAct = React.unstable_act;
TestRenderer = require('react-test-renderer');
TestAct = TestRenderer.act;
});
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('mocked scheduler', () => {
require.requireActual('scheduler/unstable_mock')
);
React = require('react');
DOMAct = require('react-dom/test-utils').act;
DOMAct = React.unstable_act;
TestRenderer = require('react-test-renderer');
TestAct = TestRenderer.act;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('ReactCache', () => {
}

ReactTestRenderer.create(<App />, {
unstable_isConcurrent: true,
isConcurrent: true,
});

await waitForAll(['Suspend! [Hi]', 'Loading...']);
Expand All @@ -141,7 +141,7 @@ describe('ReactCache', () => {
}

const root = ReactTestRenderer.create(<App />, {
unstable_isConcurrent: true,
isConcurrent: true,
});

await waitForAll(['Suspend! [Hi]', 'Loading...']);
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('ReactCache', () => {
<App />
</Suspense>,
{
unstable_isConcurrent: true,
isConcurrent: true,
},
);

Expand Down Expand Up @@ -210,7 +210,7 @@ describe('ReactCache', () => {
<AsyncText ms={100} text={3} />
</Suspense>,
{
unstable_isConcurrent: true,
isConcurrent: true,
},
);
await waitForAll(['Suspend! [1]', 'Loading...']);
Expand Down Expand Up @@ -298,7 +298,7 @@ describe('ReactCache', () => {
<App />
</Suspense>,
{
unstable_isConcurrent: true,
isConcurrent: true,
},
);

Expand Down Expand Up @@ -356,7 +356,7 @@ describe('ReactCache', () => {
<BadAsyncText text="Hi" />
</Suspense>,
{
unstable_isConcurrent: true,
isConcurrent: true,
},
);

Expand All @@ -372,7 +372,7 @@ describe('ReactCache', () => {
<BadAsyncText text="Hi" />
</Suspense>,
{
unstable_isConcurrent: true,
isConcurrent: true,
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ describe('React hooks DevTools integration', () => {
<MyComponent />
</React.Suspense>
</div>,
{unstable_isConcurrent: true},
{isConcurrent: true},
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('InspectedElement', () => {
// Used by inspectElementAtIndex() helper function
utils.act(() => {
testRendererInstance = TestRenderer.create(null, {
unstable_isConcurrent: true,
isConcurrent: true,
});
});

Expand Down Expand Up @@ -307,7 +307,7 @@ describe('InspectedElement', () => {
['An update to %s inside a test was not wrapped in act'],
() => {
testRendererInstance = TestRenderer.create(null, {
unstable_isConcurrent: true,
isConcurrent: true,
});
},
);
Expand Down Expand Up @@ -469,7 +469,7 @@ describe('InspectedElement', () => {
['An update to %s inside a test was not wrapped in act'],
() => {
testRendererInstance = TestRenderer.create(null, {
unstable_isConcurrent: true,
isConcurrent: true,
});
},
);
Expand Down Expand Up @@ -2034,7 +2034,7 @@ describe('InspectedElement', () => {
['An update to %s inside a test was not wrapped in act'],
() => {
testRendererInstance = TestRenderer.create(null, {
unstable_isConcurrent: true,
isConcurrent: true,
});
},
);
Expand Down Expand Up @@ -2317,7 +2317,7 @@ describe('InspectedElement', () => {
<Suspender target={id} />
</React.Suspense>
</Contexts>,
{unstable_isConcurrent: true},
{isConcurrent: true},
);
}, false);
await utils.actAsync(() => {
Expand Down Expand Up @@ -2817,7 +2817,7 @@ describe('InspectedElement', () => {
['An update to %s inside a test was not wrapped in act'],
() => {
testRendererInstance = TestRenderer.create(null, {
unstable_isConcurrent: true,
isConcurrent: true,
});
},
);
Expand Down
4 changes: 2 additions & 2 deletions packages/react-devtools-shared/src/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function act(
recursivelyFlush: boolean = true,
): void {
const {act: actTestRenderer} = require('react-test-renderer');
const {act: actDOM} = require('react-dom/test-utils');
const actDOM = require('react').unstable_act;

actDOM(() => {
actTestRenderer(() => {
Expand All @@ -44,7 +44,7 @@ export async function actAsync(
recursivelyFlush: boolean = true,
): Promise<void> {
const {act: actTestRenderer} = require('react-test-renderer');
const {act: actDOM} = require('react-dom/test-utils');
const actDOM = require('react').unstable_act;

await actDOM(async () => {
await actTestRenderer(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('ReactDOMServerHydration', () => {
React = require('react');
ReactDOMClient = require('react-dom/client');
ReactDOMServer = require('react-dom/server');
act = require('react-dom/test-utils').act;
act = React.unstable_act;

console.error = jest.fn();
container = document.createElement('div');
Expand Down
15 changes: 12 additions & 3 deletions packages/react-dom/src/__tests__/ReactDOMInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,32 @@ describe('ReactDOMInput', () => {
expect(() => {
ReactDOM.render(<input type="text" value={0} />, container);
}).toErrorDev(
'Warning: You provided a `value` prop to a form field without an `onChange` handler.',
'Warning: You provided a `value` prop to a form ' +
'field without an `onChange` handler. This will render a read-only ' +
'field. If the field should be mutable use `defaultValue`. ' +
'Otherwise, set either `onChange` or `readOnly`.',
);
});

it('should warn for controlled value of "" with missing onChange', () => {
expect(() => {
ReactDOM.render(<input type="text" value="" />, container);
}).toErrorDev(
'Warning: You provided a `value` prop to a form field without an `onChange` handler.',
'Warning: You provided a `value` prop to a form ' +
'field without an `onChange` handler. This will render a read-only ' +
'field. If the field should be mutable use `defaultValue`. ' +
'Otherwise, set either `onChange` or `readOnly`.',
);
});

it('should warn for controlled value of "0" with missing onChange', () => {
expect(() => {
ReactDOM.render(<input type="text" value="0" />, container);
}).toErrorDev(
'Warning: You provided a `value` prop to a form field without an `onChange` handler.',
'Warning: You provided a `value` prop to a form ' +
'field without an `onChange` handler. This will render a read-only ' +
'field. If the field should be mutable use `defaultValue`. ' +
'Otherwise, set either `onChange` or `readOnly`.',
);
});

Expand Down
81 changes: 81 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMTextarea-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,4 +759,85 @@ describe('ReactDOMTextarea', () => {
ReactDOM.render(<textarea defaultValue={null} />, container);
expect(node.defaultValue).toBe('');
});

it('should not warn about missing onChange if value is not set', () => {
expect(() => {
ReactTestUtils.renderIntoDocument(<textarea />);
}).not.toThrow();
});

it('should not warn about missing onChange if value is undefined', () => {
expect(() => {
ReactTestUtils.renderIntoDocument(<textarea value={undefined} />);
}).not.toThrow();
});

it('should not warn about missing onChange if onChange is set', () => {
expect(() => {
const change = jest.fn();
ReactTestUtils.renderIntoDocument(
<textarea value="something" onChange={change} />,
);
}).not.toThrow();
});

it('should not warn about missing onChange if disabled is true', () => {
expect(() => {
ReactTestUtils.renderIntoDocument(
<textarea value="something" disabled={true} />,
);
}).not.toThrow();
});

it('should not warn about missing onChange if value is not set', () => {
expect(() => {
ReactTestUtils.renderIntoDocument(
<textarea value="something" readOnly={true} />,
);
}).not.toThrow();
});

it('should warn about missing onChange if value is false', () => {
expect(() =>
ReactTestUtils.renderIntoDocument(<textarea value={false} />),
).toErrorDev(
'Warning: You provided a `value` prop to a form ' +
'field without an `onChange` handler. This will render a read-only ' +
'field. If the field should be mutable use `defaultValue`. ' +
'Otherwise, set either `onChange` or `readOnly`.',
);
});

it('should warn about missing onChange if value is 0', () => {
expect(() =>
ReactTestUtils.renderIntoDocument(<textarea value={0} />),
).toErrorDev(
'Warning: You provided a `value` prop to a form ' +
'field without an `onChange` handler. This will render a read-only ' +
'field. If the field should be mutable use `defaultValue`. ' +
'Otherwise, set either `onChange` or `readOnly`.',
);
});

it('should warn about missing onChange if value is "0"', () => {
expect(() =>
ReactTestUtils.renderIntoDocument(<textarea value="0" />),
).toErrorDev(
'Warning: You provided a `value` prop to a form ' +
'field without an `onChange` handler. This will render a read-only ' +
'field. If the field should be mutable use `defaultValue`. ' +
'Otherwise, set either `onChange` or `readOnly`.',
);
});

it('should warn about missing onChange if value is ""', () => {
expect(() =>
ReactTestUtils.renderIntoDocument(<textarea value="" />),
).toErrorDev(
'Warning: You provided a `value` prop to a form ' +
'field without an `onChange` handler. This will render a read-only ' +
'field. If the field should be mutable use `defaultValue`. ' +
'Otherwise, set either `onChange` or `readOnly`.',
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ beforeEach(() => {
yields = [];
React = require('react');
ReactDOM = require('react-dom');
act = require('react-dom/test-utils').act;
act = React.unstable_act;
container = document.createElement('div');
document.body.appendChild(container);
});
Expand Down
15 changes: 11 additions & 4 deletions packages/react-reconciler/src/ReactFiberLane.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import {
enableTransitionTracing,
enableUnifiedSyncLane,
enableUpdaterTracking,
syncLaneExpirationMs,
transitionLaneExpirationMs,
retryLaneExpirationMs,
} from 'shared/ReactFeatureFlags';
import {isDevToolsPresent} from './ReactFiberDevToolsHook';
import {ConcurrentUpdatesByDefaultMode, NoMode} from './ReactTypeOfMode';
Expand Down Expand Up @@ -355,7 +358,7 @@ function computeExpirationTime(lane: Lane, currentTime: number) {
// to fix the starvation. However, this scenario supports the idea that
// expiration times are an important safeguard when starvation
// does happen.
return currentTime + 250;
return currentTime + syncLaneExpirationMs;
case DefaultHydrationLane:
case DefaultLane:
case TransitionHydrationLane:
Expand All @@ -374,7 +377,7 @@ function computeExpirationTime(lane: Lane, currentTime: number) {
case TransitionLane13:
case TransitionLane14:
case TransitionLane15:
return currentTime + 5000;
return currentTime + transitionLaneExpirationMs;
case RetryLane1:
case RetryLane2:
case RetryLane3:
Expand All @@ -384,7 +387,9 @@ function computeExpirationTime(lane: Lane, currentTime: number) {
// crashes. There must be some other underlying bug; not super urgent but
// ideally should figure out why and fix it. Unfortunately we don't have
// a repro for the crashes, only detected via production metrics.
return enableRetryLaneExpiration ? currentTime + 5000 : NoTimestamp;
return enableRetryLaneExpiration
? currentTime + retryLaneExpirationMs
: NoTimestamp;
case SelectiveHydrationLane:
case IdleHydrationLane:
case IdleLane:
Expand Down Expand Up @@ -423,7 +428,9 @@ export function markStarvedLanesAsExpired(
// We exclude retry lanes because those must always be time sliced, in order
// to unwrap uncached promises.
// TODO: Write a test for this
let lanes = pendingLanes & ~RetryLanes;
let lanes = enableRetryLaneExpiration
? pendingLanes
: pendingLanes & ~RetryLanes;
while (lanes > 0) {
const index = pickArbitraryLaneIndex(lanes);
const lane = 1 << index;
Expand Down
Loading

0 comments on commit bf9d240

Please sign in to comment.