Skip to content

Commit 6c4d404

Browse files
committed
Remove unstable_changedBits
We added this unstable feature a few years ago, as a way to opt out of context updates, but it didn't prove useful in practice. We have other proposals for how to address the same problem, like context selectors. Since it was prefixed with `unstable_`, we should be able to remove it without consequence. The hook API already warned if you used it. Even if someone is using it somewhere, it's meant to be an optimization only, so if they are using the API properly, it should not have any semantic impact.
1 parent 5fe091c commit 6c4d404

14 files changed

+113
-697
lines changed

packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -736,17 +736,6 @@ describe('ReactDOMServerHooks', () => {
736736
},
737737
);
738738

739-
itRenders('warns when bitmask is passed to useContext', async render => {
740-
const Context = React.createContext('Hi');
741-
742-
function Foo() {
743-
return <span>{useContext(Context, 1)}</span>;
744-
}
745-
746-
const domNode = await render(<Foo />, 1);
747-
expect(domNode.textContent).toBe('Hi');
748-
});
749-
750739
describe('useDebugValue', () => {
751740
itRenders('is a noop', async render => {
752741
function Counter(props) {
@@ -760,11 +749,11 @@ describe('ReactDOMServerHooks', () => {
760749
});
761750

762751
describe('readContext', () => {
763-
function readContext(Context, observedBits) {
752+
function readContext(Context) {
764753
const dispatcher =
765754
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
766755
.ReactCurrentDispatcher.current;
767-
return dispatcher.readContext(Context, observedBits);
756+
return dispatcher.readContext(Context);
768757
}
769758

770759
itRenders(

packages/react-reconciler/src/ReactFiberBeginWork.new.js

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ import {
160160
checkIfContextChanged,
161161
readContext,
162162
prepareToReadContext,
163-
calculateChangedBits,
164163
scheduleWorkOnParentPath,
165164
} from './ReactFiberNewContext.new';
166165
import {renderWithHooks, bailoutHooks} from './ReactFiberHooks.new';
@@ -221,7 +220,7 @@ import {
221220
restoreSpawnedCachePool,
222221
getOffscreenDeferredCachePool,
223222
} from './ReactFiberCacheComponent.new';
224-
import {MAX_SIGNED_31_BIT_INT} from './MaxInts';
223+
import is from 'shared/objectIs';
225224

226225
import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';
227226

@@ -796,12 +795,7 @@ function updateCacheComponent(
796795
pushCacheProvider(workInProgress, nextCache);
797796
if (nextCache !== prevState.cache) {
798797
// This cache refreshed. Propagate a context change.
799-
propagateContextChange(
800-
workInProgress,
801-
CacheContext,
802-
MAX_SIGNED_31_BIT_INT,
803-
renderLanes,
804-
);
798+
propagateContextChange(workInProgress, CacheContext, renderLanes);
805799
}
806800
}
807801
}
@@ -1168,12 +1162,7 @@ function updateHostRoot(current, workInProgress, renderLanes) {
11681162
pushCacheProvider(workInProgress, nextCache);
11691163
if (nextCache !== prevState.cache) {
11701164
// The root cache refreshed.
1171-
propagateContextChange(
1172-
workInProgress,
1173-
CacheContext,
1174-
MAX_SIGNED_31_BIT_INT,
1175-
renderLanes,
1176-
);
1165+
propagateContextChange(workInProgress, CacheContext, renderLanes);
11771166
}
11781167
}
11791168

@@ -3007,8 +2996,7 @@ function updateContextProvider(
30072996
} else {
30082997
if (oldProps !== null) {
30092998
const oldValue = oldProps.value;
3010-
const changedBits = calculateChangedBits(context, newValue, oldValue);
3011-
if (changedBits === 0) {
2999+
if (is(oldValue, newValue)) {
30123000
// No change. Bailout early if children are the same.
30133001
if (
30143002
oldProps.children === newProps.children &&
@@ -3023,12 +3011,7 @@ function updateContextProvider(
30233011
} else {
30243012
// The context value changed. Search for matching consumers and schedule
30253013
// them to update.
3026-
propagateContextChange(
3027-
workInProgress,
3028-
context,
3029-
changedBits,
3030-
renderLanes,
3031-
);
3014+
propagateContextChange(workInProgress, context, renderLanes);
30323015
}
30333016
}
30343017
}
@@ -3086,7 +3069,7 @@ function updateContextConsumer(
30863069
}
30873070

30883071
prepareToReadContext(workInProgress, renderLanes);
3089-
const newValue = readContext(context, newProps.unstable_observedBits);
3072+
const newValue = readContext(context);
30903073
let newChildren;
30913074
if (__DEV__) {
30923075
ReactCurrentOwner.current = workInProgress;

packages/react-reconciler/src/ReactFiberBeginWork.old.js

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ import {
160160
checkIfContextChanged,
161161
readContext,
162162
prepareToReadContext,
163-
calculateChangedBits,
164163
scheduleWorkOnParentPath,
165164
} from './ReactFiberNewContext.old';
166165
import {renderWithHooks, bailoutHooks} from './ReactFiberHooks.old';
@@ -221,7 +220,7 @@ import {
221220
restoreSpawnedCachePool,
222221
getOffscreenDeferredCachePool,
223222
} from './ReactFiberCacheComponent.old';
224-
import {MAX_SIGNED_31_BIT_INT} from './MaxInts';
223+
import is from 'shared/objectIs';
225224

226225
import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';
227226

@@ -796,12 +795,7 @@ function updateCacheComponent(
796795
pushCacheProvider(workInProgress, nextCache);
797796
if (nextCache !== prevState.cache) {
798797
// This cache refreshed. Propagate a context change.
799-
propagateContextChange(
800-
workInProgress,
801-
CacheContext,
802-
MAX_SIGNED_31_BIT_INT,
803-
renderLanes,
804-
);
798+
propagateContextChange(workInProgress, CacheContext, renderLanes);
805799
}
806800
}
807801
}
@@ -1168,12 +1162,7 @@ function updateHostRoot(current, workInProgress, renderLanes) {
11681162
pushCacheProvider(workInProgress, nextCache);
11691163
if (nextCache !== prevState.cache) {
11701164
// The root cache refreshed.
1171-
propagateContextChange(
1172-
workInProgress,
1173-
CacheContext,
1174-
MAX_SIGNED_31_BIT_INT,
1175-
renderLanes,
1176-
);
1165+
propagateContextChange(workInProgress, CacheContext, renderLanes);
11771166
}
11781167
}
11791168

@@ -3007,8 +2996,7 @@ function updateContextProvider(
30072996
} else {
30082997
if (oldProps !== null) {
30092998
const oldValue = oldProps.value;
3010-
const changedBits = calculateChangedBits(context, newValue, oldValue);
3011-
if (changedBits === 0) {
2999+
if (is(oldValue, newValue)) {
30123000
// No change. Bailout early if children are the same.
30133001
if (
30143002
oldProps.children === newProps.children &&
@@ -3023,12 +3011,7 @@ function updateContextProvider(
30233011
} else {
30243012
// The context value changed. Search for matching consumers and schedule
30253013
// them to update.
3026-
propagateContextChange(
3027-
workInProgress,
3028-
context,
3029-
changedBits,
3030-
renderLanes,
3031-
);
3014+
propagateContextChange(workInProgress, context, renderLanes);
30323015
}
30333016
}
30343017
}
@@ -3086,7 +3069,7 @@ function updateContextConsumer(
30863069
}
30873070

30883071
prepareToReadContext(workInProgress, renderLanes);
3089-
const newValue = readContext(context, newProps.unstable_observedBits);
3072+
const newValue = readContext(context);
30903073
let newChildren;
30913074
if (__DEV__) {
30923075
ReactCurrentOwner.current = workInProgress;

packages/react-reconciler/src/ReactFiberCacheComponent.new.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export const CacheContext: ReactContext<Cache> = enableCache
3737
// We don't use Consumer/Provider for Cache components. So we'll cheat.
3838
Consumer: (null: any),
3939
Provider: (null: any),
40-
_calculateChangedBits: null,
4140
// We'll initialize these at the root.
4241
_currentValue: (null: any),
4342
_currentValue2: (null: any),

packages/react-reconciler/src/ReactFiberCacheComponent.old.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export const CacheContext: ReactContext<Cache> = enableCache
3737
// We don't use Consumer/Provider for Cache components. So we'll cheat.
3838
Consumer: (null: any),
3939
Provider: (null: any),
40-
_calculateChangedBits: null,
4140
// We'll initialize these at the root.
4241
_currentValue: (null: any),
4342
_currentValue2: (null: any),

0 commit comments

Comments
 (0)