Skip to content

Commit 5635280

Browse files
committed
Remove useId semantics from View Transition name generation
1 parent ee7fee8 commit 5635280

File tree

4 files changed

+15
-63
lines changed

4 files changed

+15
-63
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import type {
3737
OffscreenInstance,
3838
} from './ReactFiberOffscreenComponent';
3939
import type {ViewTransitionState} from './ReactFiberViewTransitionComponent';
40-
import {assignViewTransitionAutoName} from './ReactFiberViewTransitionComponent';
4140
import type {
4241
Cache,
4342
CacheComponentState,
@@ -3538,24 +3537,13 @@ function updateViewTransition(
35383537
renderLanes: Lanes,
35393538
) {
35403539
const pendingProps: ViewTransitionProps = workInProgress.pendingProps;
3541-
const instance: ViewTransitionState = workInProgress.stateNode;
35423540
if (pendingProps.name != null && pendingProps.name !== 'auto') {
35433541
// Explicitly named boundary. We track it so that we can pair it up with another explicit
35443542
// boundary if we get deleted.
35453543
workInProgress.flags |=
35463544
current === null
35473545
? ViewTransitionNamedMount | ViewTransitionNamedStatic
35483546
: ViewTransitionNamedStatic;
3549-
} else {
3550-
// Assign an auto generated name using the useId algorthim if an explicit one is not provided.
3551-
// We don't need the name yet but we do it here to allow hydration state to be used.
3552-
// We might end up needing these to line up if we want to Transition from dehydrated fallback
3553-
// to client rendered content. If we don't end up using that we could just assign an incremeting
3554-
// counter in the commit phase instead.
3555-
assignViewTransitionAutoName(pendingProps, instance);
3556-
if (getIsHydrating()) {
3557-
pushMaterializedTreeId(workInProgress);
3558-
}
35593547
}
35603548
if (__DEV__) {
35613549
// $FlowFixMe[prop-missing]

packages/react-reconciler/src/ReactFiberViewTransitionComponent.js

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@ import type {FiberRoot} from './ReactInternalTypes';
1212
import type {ViewTransitionInstance, Instance} from './ReactFiberConfig';
1313

1414
import {
15-
getWorkInProgressRoot,
15+
getCommittingRoot,
1616
getPendingTransitionTypes,
1717
} from './ReactFiberWorkLoop';
1818

19-
import {getIsHydrating} from './ReactFiberHydrationContext';
20-
21-
import {getTreeId} from './ReactFiberTreeContext';
22-
2319
export type ViewTransitionState = {
2420
autoName: null | string, // the view-transition-name to use when an explicit one is not specified
2521
paired: null | ViewTransitionState, // a temporary state during the commit phase if we have paired this with another instance
@@ -29,47 +25,27 @@ export type ViewTransitionState = {
2925

3026
let globalClientIdCounter: number = 0;
3127

32-
export function assignViewTransitionAutoName(
28+
export function getViewTransitionName(
3329
props: ViewTransitionProps,
3430
instance: ViewTransitionState,
3531
): string {
32+
if (props.name != null && props.name !== 'auto') {
33+
return props.name;
34+
}
3635
if (instance.autoName !== null) {
3736
return instance.autoName;
3837
}
3938

40-
const root = ((getWorkInProgressRoot(): any): FiberRoot);
39+
// We assume we always call this in the commit phase.
40+
const root = ((getCommittingRoot(): any): FiberRoot);
4141
const identifierPrefix = root.identifierPrefix;
42-
43-
let name;
44-
if (getIsHydrating()) {
45-
const treeId = getTreeId();
46-
// Use a captial R prefix for server-generated ids.
47-
name = '\u00AB' + identifierPrefix + 'T' + treeId + '\u00BB';
48-
} else {
49-
// Use a lowercase r prefix for client-generated ids.
50-
const globalClientId = globalClientIdCounter++;
51-
name =
52-
'\u00AB' +
53-
identifierPrefix +
54-
't' +
55-
globalClientId.toString(32) +
56-
'\u00BB';
57-
}
42+
const globalClientId = globalClientIdCounter++;
43+
const name =
44+
'\u00AB' + identifierPrefix + 't' + globalClientId.toString(32) + '\u00BB';
5845
instance.autoName = name;
5946
return name;
6047
}
6148

62-
export function getViewTransitionName(
63-
props: ViewTransitionProps,
64-
instance: ViewTransitionState,
65-
): string {
66-
if (props.name != null && props.name !== 'auto') {
67-
return props.name;
68-
}
69-
// We should have assigned a name by now.
70-
return (instance.autoName: any);
71-
}
72-
7349
function getClassNameByType(classByType: ?ViewTransitionClass): ?string {
7450
if (classByType == null || typeof classByType === 'string') {
7551
return classByType;

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,10 @@ export function getWorkInProgressRoot(): FiberRoot | null {
699699
return workInProgressRoot;
700700
}
701701

702+
export function getCommittingRoot(): FiberRoot | null {
703+
return pendingEffectsRoot;
704+
}
705+
702706
export function getWorkInProgressRootRenderLanes(): Lanes {
703707
return workInProgressRootRenderLanes;
704708
}

packages/react-server/src/ReactFizzServer.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,23 +2274,7 @@ function renderViewTransition(
22742274
) {
22752275
const prevKeyPath = task.keyPath;
22762276
task.keyPath = keyPath;
2277-
if (props.name != null && props.name !== 'auto') {
2278-
renderNodeDestructive(request, task, props.children, -1);
2279-
} else {
2280-
// This will be auto-assigned a name which claims a "useId" slot.
2281-
// This component materialized an id. We treat this as its own level, with
2282-
// a single "child" slot.
2283-
const prevTreeContext = task.treeContext;
2284-
const totalChildren = 1;
2285-
const index = 0;
2286-
// Modify the id context. Because we'll need to reset this if something
2287-
// suspends or errors, we'll use the non-destructive render path.
2288-
task.treeContext = pushTreeContext(prevTreeContext, totalChildren, index);
2289-
renderNode(request, task, props.children, -1);
2290-
// Like the other contexts, this does not need to be in a finally block
2291-
// because renderNode takes care of unwinding the stack.
2292-
task.treeContext = prevTreeContext;
2293-
}
2277+
renderNodeDestructive(request, task, props.children, -1);
22942278
task.keyPath = prevKeyPath;
22952279
}
22962280

0 commit comments

Comments
 (0)