mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 00:20:04 +01:00
Release Fragment refs to Canary (#34720)
## Overview This PR adds the `ref` prop to `<Fragment>` in `react@canary`. This means this API is ready for final feedback and prepared for a semver stable release. ## What this means Shipping Fragment refs to canary means they have gone through extensive testing in production, we are confident in the stability of the APIs, and we are preparing to release it in a future semver stable version. Libraries and frameworks following the [Canary Workflow](https://react.dev/blog/2023/05/03/react-canaries) should begin implementing and testing these features. ## Why we follow the Canary Workflow To prepare for semver stable, libraries should test canary features like Fragment refs with `react@canary` to confirm compatibility and prepare for the next semver release in a myriad of environments and configurations used throughout the React ecosystem. This provides libraries with ample time to catch any issues we missed before slamming them with problems in the wider semver release. Since these features have already gone through extensive production testing, and we are confident they are stable, frameworks following the [Canary Workflow](https://react.dev/blog/2023/05/03/react-canaries) can also begin adopting canary features like Fragment refs. This adoption is similar to how different Browsers implement new proposed browser features before they are added to the standard. If a frameworks adopts a canary feature, they are committing to stability for their users by ensuring any API changes before a semver stable release are opaque and non-breaking to their users. Apps not using a framework are also free to adopt canary features like Fragment refs as long as they follow the [Canary Workflow](https://react.dev/blog/2023/05/03/react-canaries), but we generally recommend waiting for a semver stable release unless you have the capacity to commit to following along with the canary changes and debugging library compatibility issues. Waiting for semver stable means you're able to benefit from libraries testing and confirming support, and use semver as signal for which version of a library you can use with support of the feature. ## Docs Check out the ["React Labs: View Transitions, Activity, and more"](https://react.dev/blog/2025/04/23/react-labs-view-transitions-activity-and-more#fragment-refs) blog post, and [the new docs for Fragment refs`](https://react.dev/reference/react/Fragment#fragmentinstance) for more info.
This commit is contained in:
parent
6a8c7fb6f1
commit
a4eb2dfa6f
|
|
@ -55,11 +55,11 @@ export default function ScrollIntoViewCase() {
|
|||
const scrollContainerRef = useRef(null);
|
||||
|
||||
const scrollVertical = () => {
|
||||
fragmentRef.current.experimental_scrollIntoView(alignToTop);
|
||||
fragmentRef.current.scrollIntoView(alignToTop);
|
||||
};
|
||||
|
||||
const scrollVerticalNoChildren = () => {
|
||||
noChildRef.current.experimental_scrollIntoView(alignToTop);
|
||||
noChildRef.current.scrollIntoView(alignToTop);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
|||
|
|
@ -3341,13 +3341,13 @@ function validateDocumentPositionWithFiberTree(
|
|||
|
||||
if (enableFragmentRefsScrollIntoView) {
|
||||
// $FlowFixMe[prop-missing]
|
||||
FragmentInstance.prototype.experimental_scrollIntoView = function (
|
||||
FragmentInstance.prototype.scrollIntoView = function (
|
||||
this: FragmentInstanceType,
|
||||
alignToTop?: boolean,
|
||||
): void {
|
||||
if (typeof alignToTop === 'object') {
|
||||
throw new Error(
|
||||
'FragmentInstance.experimental_scrollIntoView() does not support ' +
|
||||
'FragmentInstance.scrollIntoView() does not support ' +
|
||||
'scrollIntoViewOptions. Use the alignToTop boolean instead.',
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1960,9 +1960,9 @@ describe('FragmentRefs', () => {
|
|||
});
|
||||
|
||||
expect(() => {
|
||||
fragmentRef.current.experimental_scrollIntoView({block: 'start'});
|
||||
fragmentRef.current.scrollIntoView({block: 'start'});
|
||||
}).toThrowError(
|
||||
'FragmentInstance.experimental_scrollIntoView() does not support ' +
|
||||
'FragmentInstance.scrollIntoView() does not support ' +
|
||||
'scrollIntoViewOptions. Use the alignToTop boolean instead.',
|
||||
);
|
||||
});
|
||||
|
|
@ -1996,11 +1996,11 @@ describe('FragmentRefs', () => {
|
|||
});
|
||||
|
||||
// Default call
|
||||
fragmentRef.current.experimental_scrollIntoView();
|
||||
fragmentRef.current.scrollIntoView();
|
||||
expectLast(logs, 'childA');
|
||||
logs = [];
|
||||
// alignToTop=true
|
||||
fragmentRef.current.experimental_scrollIntoView(true);
|
||||
fragmentRef.current.scrollIntoView(true);
|
||||
expectLast(logs, 'childA');
|
||||
});
|
||||
|
||||
|
|
@ -2027,7 +2027,7 @@ describe('FragmentRefs', () => {
|
|||
logs.push('childB');
|
||||
});
|
||||
|
||||
fragmentRef.current.experimental_scrollIntoView(false);
|
||||
fragmentRef.current.scrollIntoView(false);
|
||||
expectLast(logs, 'childB');
|
||||
});
|
||||
|
||||
|
|
@ -2068,7 +2068,7 @@ describe('FragmentRefs', () => {
|
|||
});
|
||||
|
||||
// Default call
|
||||
fragmentRef.current.experimental_scrollIntoView();
|
||||
fragmentRef.current.scrollIntoView();
|
||||
expectLast(logs, 'childA');
|
||||
});
|
||||
|
||||
|
|
@ -2157,7 +2157,7 @@ describe('FragmentRefs', () => {
|
|||
});
|
||||
|
||||
// Default call
|
||||
fragmentRef.current.experimental_scrollIntoView();
|
||||
fragmentRef.current.scrollIntoView();
|
||||
expectLast(logs, 'header');
|
||||
|
||||
childARef.current.scrollIntoView.mockClear();
|
||||
|
|
@ -2167,7 +2167,7 @@ describe('FragmentRefs', () => {
|
|||
logs = [];
|
||||
|
||||
// // alignToTop=false
|
||||
fragmentRef.current.experimental_scrollIntoView(false);
|
||||
fragmentRef.current.scrollIntoView(false);
|
||||
expectLast(logs, 'C');
|
||||
});
|
||||
});
|
||||
|
|
@ -2195,14 +2195,14 @@ describe('FragmentRefs', () => {
|
|||
siblingBRef.current.scrollIntoView = jest.fn();
|
||||
|
||||
// Default call
|
||||
fragmentRef.current.experimental_scrollIntoView();
|
||||
fragmentRef.current.scrollIntoView();
|
||||
expect(siblingARef.current.scrollIntoView).toHaveBeenCalledTimes(0);
|
||||
expect(siblingBRef.current.scrollIntoView).toHaveBeenCalledTimes(1);
|
||||
|
||||
siblingBRef.current.scrollIntoView.mockClear();
|
||||
|
||||
// alignToTop=true
|
||||
fragmentRef.current.experimental_scrollIntoView(true);
|
||||
fragmentRef.current.scrollIntoView(true);
|
||||
expect(siblingARef.current.scrollIntoView).toHaveBeenCalledTimes(0);
|
||||
expect(siblingBRef.current.scrollIntoView).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
|
@ -2239,7 +2239,7 @@ describe('FragmentRefs', () => {
|
|||
siblingBRef.current.scrollIntoView = jest.fn();
|
||||
|
||||
// alignToTop=false
|
||||
fragmentRef.current.experimental_scrollIntoView(false);
|
||||
fragmentRef.current.scrollIntoView(false);
|
||||
expect(siblingARef.current.scrollIntoView).toHaveBeenCalledTimes(1);
|
||||
expect(siblingBRef.current.scrollIntoView).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
|
@ -2260,7 +2260,7 @@ describe('FragmentRefs', () => {
|
|||
});
|
||||
|
||||
parentRef.current.scrollIntoView = jest.fn();
|
||||
fragmentRef.current.experimental_scrollIntoView();
|
||||
fragmentRef.current.scrollIntoView();
|
||||
expect(parentRef.current.scrollIntoView).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -145,8 +145,8 @@ export const transitionLaneExpirationMs = 5000;
|
|||
*/
|
||||
export const enableInfiniteRenderLoopDetection: boolean = false;
|
||||
|
||||
export const enableFragmentRefs = __EXPERIMENTAL__;
|
||||
export const enableFragmentRefsScrollIntoView = __EXPERIMENTAL__;
|
||||
export const enableFragmentRefs: boolean = true;
|
||||
export const enableFragmentRefsScrollIntoView: boolean = true;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Ready for next major.
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ export const enableHydrationChangeEvent: boolean = false;
|
|||
export const enableDefaultTransitionIndicator: boolean = false;
|
||||
export const ownerStackLimit = 1e4;
|
||||
|
||||
export const enableFragmentRefs: boolean = false;
|
||||
export const enableFragmentRefs: boolean = true;
|
||||
export const enableFragmentRefsScrollIntoView: boolean = false;
|
||||
|
||||
// Profiling Only
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ export const enableHydrationChangeEvent: boolean = false;
|
|||
export const enableDefaultTransitionIndicator: boolean = false;
|
||||
export const ownerStackLimit = 1e4;
|
||||
|
||||
export const enableFragmentRefs: boolean = false;
|
||||
export const enableFragmentRefsScrollIntoView: boolean = false;
|
||||
export const enableFragmentRefs: boolean = true;
|
||||
export const enableFragmentRefsScrollIntoView: boolean = true;
|
||||
|
||||
// TODO: This must be in sync with the main ReactFeatureFlags file because
|
||||
// the Test Renderer's value must be the same as the one used by the
|
||||
|
|
|
|||
|
|
@ -551,5 +551,5 @@
|
|||
"563": "This render completed successfully. All cacheSignals are now aborted to allow clean up of any unused resources.",
|
||||
"564": "Unknown command. The debugChannel was not wired up properly.",
|
||||
"565": "resolveDebugMessage/closeDebugChannel should not be called for a Request that wasn't kept alive. This is a bug in React.",
|
||||
"566": "FragmentInstance.experimental_scrollIntoView() does not support scrollIntoViewOptions. Use the alignToTop boolean instead."
|
||||
"566": "FragmentInstance.scrollIntoView() does not support scrollIntoViewOptions. Use the alignToTop boolean instead."
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user