diff --git a/fixtures/unstable-async/suspense/src/components/ContributorListPage.js b/fixtures/unstable-async/suspense/src/components/ContributorListPage.js index 665418181124a..351703ffe9e7e 100644 --- a/fixtures/unstable-async/suspense/src/components/ContributorListPage.js +++ b/fixtures/unstable-async/suspense/src/components/ContributorListPage.js @@ -1,10 +1,12 @@ import React, {Fragment} from 'react'; -import {createResource} from 'react-cache'; +import {unstable_createResource} from 'react-cache'; import {cache} from '../cache'; import Spinner from './Spinner'; import {fetchCoreContributorListJSON} from '../api'; -const ContributorListResource = createResource(fetchCoreContributorListJSON); +const ContributorListResource = unstable_createResource( + fetchCoreContributorListJSON +); const ContributorListPage = ({loadingId, onUserClick}) => ( diff --git a/fixtures/unstable-async/suspense/src/components/UserPage.js b/fixtures/unstable-async/suspense/src/components/UserPage.js index 4bcffae7ab6f0..ce3526926bdb8 100644 --- a/fixtures/unstable-async/suspense/src/components/UserPage.js +++ b/fixtures/unstable-async/suspense/src/components/UserPage.js @@ -1,5 +1,5 @@ import React, {Suspense} from 'react'; -import {createResource} from 'react-cache'; +import {unstable_createResource} from 'react-cache'; import Spinner from './Spinner'; import {cache} from '../cache'; import {fetchUserProfileJSON, fetchUserRepositoriesListJSON} from '../api'; @@ -21,7 +21,7 @@ export default function UserPage({id}) { ); } -const UserDetailsResource = createResource(fetchUserProfileJSON); +const UserDetailsResource = unstable_createResource(fetchUserProfileJSON); function UserDetails({id}) { const user = UserDetailsResource.read(cache, id); @@ -103,7 +103,7 @@ const Email = ({email}) => ( ); -const ImageResource = createResource( +const ImageResource = unstable_createResource( src => new Promise(resolve => { const img = new Image(); @@ -132,7 +132,9 @@ function UserPicture({source}) { ); } -const UserRepositoriesResource = createResource(fetchUserRepositoriesListJSON); +const UserRepositoriesResource = unstable_createResource( + fetchUserRepositoriesListJSON +); function Repositories({id}) { const repos = UserRepositoriesResource.read(cache, id); diff --git a/packages/jest-react/src/JestReact.js b/packages/jest-react/src/JestReact.js index 576e8d84bad42..e7fe0eaf0bb73 100644 --- a/packages/jest-react/src/JestReact.js +++ b/packages/jest-react/src/JestReact.js @@ -30,11 +30,11 @@ function assertYieldsWereCleared(root) { invariant( actualYields.length === 0, 'Log of yielded values is not empty. ' + - 'Call expect(ReactTestRenderer).toHaveYielded(...) first.', + 'Call expect(ReactTestRenderer).unstable_toHaveYielded(...) first.', ); } -export function toFlushAndYield(root, expectedYields) { +export function unstable_toFlushAndYield(root, expectedYields) { assertYieldsWereCleared(root); const actualYields = root.unstable_flushAll(); return captureAssertion(() => { @@ -42,7 +42,7 @@ export function toFlushAndYield(root, expectedYields) { }); } -export function toFlushAndYieldThrough(root, expectedYields) { +export function unstable_toFlushAndYieldThrough(root, expectedYields) { assertYieldsWereCleared(root); const actualYields = root.unstable_flushNumberOfYields(expectedYields.length); return captureAssertion(() => { @@ -50,11 +50,11 @@ export function toFlushAndYieldThrough(root, expectedYields) { }); } -export function toFlushWithoutYielding(root) { - return toFlushAndYield(root, []); +export function unstable_toFlushWithoutYielding(root) { + return unstable_toFlushAndYield(root, []); } -export function toHaveYielded(ReactTestRenderer, expectedYields) { +export function unstable_toHaveYielded(ReactTestRenderer, expectedYields) { return captureAssertion(() => { if ( ReactTestRenderer === null || @@ -63,9 +63,9 @@ export function toHaveYielded(ReactTestRenderer, expectedYields) { ) { invariant( false, - 'The matcher `toHaveYielded` expects an instance of React Test ' + + 'The matcher `unstable_toHaveYielded` expects an instance of React Test ' + 'Renderer.\n\nTry: ' + - 'expect(ReactTestRenderer).toHaveYielded(expectedYields)', + 'expect(ReactTestRenderer).unstable_toHaveYielded(expectedYields)', ); } const actualYields = ReactTestRenderer.unstable_clearYields(); @@ -73,7 +73,7 @@ export function toHaveYielded(ReactTestRenderer, expectedYields) { }); } -export function toFlushAndThrow(root, ...rest) { +export function unstable_toFlushAndThrow(root, ...rest) { assertYieldsWereCleared(root); return captureAssertion(() => { expect(() => { @@ -82,7 +82,7 @@ export function toFlushAndThrow(root, ...rest) { }); } -export function toMatchRenderedOutput(root, expectedJSX) { +export function unstable_toMatchRenderedOutput(root, expectedJSX) { assertYieldsWereCleared(root); const actualJSON = root.toJSON(); diff --git a/packages/react-cache/src/ReactCache.js b/packages/react-cache/src/ReactCache.js index 76cf2a601aecf..98558ff9fba97 100644 --- a/packages/react-cache/src/ReactCache.js +++ b/packages/react-cache/src/ReactCache.js @@ -323,7 +323,7 @@ if (__DEV__) { '%s: Invalid key type. Expected a string, number, symbol, or boolean, ' + 'but instead received: %s' + '\n\nTo use non-primitive values as keys, you must pass a hash ' + - 'function as the second argument to createResource().', + 'function as the second argument to unstable_createResource().', methodName, key, ); @@ -341,20 +341,20 @@ type Resource = {| // were a more elegant way to do this in the function definition itself. // Primitive keys do not request a hash function. -declare function createResource( +declare function unstable_createResource( loadResource: (K) => Promise, hash?: (K) => H, ): Resource; // Non-primitive keys *do* require a hash function. // eslint-disable-next-line no-redeclare -declare function createResource( +declare function unstable_createResource( loadResource: (K) => Promise, hash: (K) => H, ): Resource; // eslint-disable-next-line no-redeclare -export function createResource( +export function unstable_createResource( loadResource: K => Promise, hash: K => H, ): Resource { diff --git a/packages/react-cache/src/__tests__/ReactCache-test.js b/packages/react-cache/src/__tests__/ReactCache-test.js index 8f70d60d9ae98..339ef6a2557a1 100644 --- a/packages/react-cache/src/__tests__/ReactCache-test.js +++ b/packages/react-cache/src/__tests__/ReactCache-test.js @@ -18,12 +18,12 @@ describe('ReactCache', () => { }); it('throws a promise if the requested value is not in the cache', async () => { - const {createCache, createResource} = ReactCache; + const {createCache, unstable_createResource} = ReactCache; function loadUpperCase(text) { return Promise.resolve(text.toUpperCase()); } - const UpperCase = createResource(loadUpperCase); + const UpperCase = unstable_createResource(loadUpperCase); const cache = createCache(); let suspender; @@ -39,7 +39,7 @@ describe('ReactCache', () => { }); it('throws an error on the subsequent read if the promise is rejected', async () => { - const {createCache, createResource} = ReactCache; + const {createCache, unstable_createResource} = ReactCache; let shouldFail = true; function loadUpperCase(text) { @@ -52,7 +52,7 @@ describe('ReactCache', () => { return Promise.resolve(text.toUpperCase()); } } - const UpperCase = createResource(loadUpperCase); + const UpperCase = unstable_createResource(loadUpperCase); const cache = createCache(); let suspender; @@ -83,12 +83,12 @@ describe('ReactCache', () => { }); it('can preload data ahead of time', async () => { - const {createCache, createResource} = ReactCache; + const {createCache, unstable_createResource} = ReactCache; function loadUpperCase(text) { return Promise.resolve(text.toUpperCase()); } - const UpperCase = createResource(loadUpperCase); + const UpperCase = unstable_createResource(loadUpperCase); const cache = createCache(); UpperCase.preload(cache, 'hello'); @@ -99,12 +99,12 @@ describe('ReactCache', () => { }); it('does not throw if preloaded promise rejects', async () => { - const {createCache, createResource} = ReactCache; + const {createCache, unstable_createResource} = ReactCache; function loadUpperCase(text) { return Promise.reject(new Error('uh oh')); } - const UpperCase = createResource(loadUpperCase); + const UpperCase = unstable_createResource(loadUpperCase); const cache = createCache(); UpperCase.preload(cache, 'hello'); @@ -115,7 +115,7 @@ describe('ReactCache', () => { }); it('accepts custom hash function', async () => { - const {createCache, createResource} = ReactCache; + const {createCache, unstable_createResource} = ReactCache; function loadSum([a, b]) { return Promise.resolve(a + b); @@ -123,7 +123,7 @@ describe('ReactCache', () => { function hash([a, b]) { return `${a + b}`; } - const Sum = createResource(loadSum, hash); + const Sum = unstable_createResource(loadSum, hash); const cache = createCache(); Sum.preload(cache, [5, 5]); @@ -166,7 +166,7 @@ describe('ReactCache', () => { }); it('warns if non-primitive key is passed to a resource without a hash function', () => { - const {createCache, createResource} = ReactCache; + const {createCache, unstable_createResource} = ReactCache; spyOnDev(console, 'error'); @@ -174,7 +174,7 @@ describe('ReactCache', () => { return Promise.resolve(a + b); } - const Sum = createResource(loadSum); + const Sum = unstable_createResource(loadSum); const cache = createCache(); function fn() { @@ -187,7 +187,7 @@ describe('ReactCache', () => { 'preload: Invalid key type. Expected a string, number, symbol, or ' + 'boolean, but instead received: 5,5\n\n' + 'To use non-primitive values as keys, you must pass a hash ' + - 'function as the second argument to createResource().', + 'function as the second argument to unstable_createResource().', ], {withoutStack: true}, ); @@ -197,12 +197,12 @@ describe('ReactCache', () => { }); it('stays within maximum capacity by evicting the least recently used record', async () => { - const {createCache, createResource} = ReactCache; + const {createCache, unstable_createResource} = ReactCache; function loadIntegerString(int) { return Promise.resolve(int + ''); } - const IntegerStringResource = createResource(loadIntegerString); + const IntegerStringResource = unstable_createResource(loadIntegerString); const cache = createCache(); // TODO: This is hard-coded to a maximum size of 500. Make this configurable diff --git a/packages/react-dom/src/__tests__/ReactDOMSuspensePlaceholder-test.internal.js b/packages/react-dom/src/__tests__/ReactDOMSuspensePlaceholder-test.internal.js index e69555b175f36..556a6202b165e 100644 --- a/packages/react-dom/src/__tests__/ReactDOMSuspensePlaceholder-test.internal.js +++ b/packages/react-dom/src/__tests__/ReactDOMSuspensePlaceholder-test.internal.js @@ -31,7 +31,7 @@ describe('ReactDOMSuspensePlaceholder', () => { cache = ReactCache.createCache(invalidateCache); } invalidateCache(); - TextResource = ReactCache.createResource(([text, ms = 0]) => { + TextResource = ReactCache.unstable_createResource(([text, ms = 0]) => { return new Promise((resolve, reject) => setTimeout(() => { resolve(text); diff --git a/packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js b/packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js index 305b740874559..bdbab58ac71b9 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js @@ -29,7 +29,7 @@ describe('ReactSuspense', () => { cache = ReactCache.createCache(invalidateCache); } invalidateCache(); - TextResource = ReactCache.createResource(([text, ms = 0]) => { + TextResource = ReactCache.unstable_createResource(([text, ms = 0]) => { let listeners = null; let status = 'pending'; let value = null; diff --git a/packages/react-reconciler/src/__tests__/ReactSuspensePlaceholder-test.internal.js b/packages/react-reconciler/src/__tests__/ReactSuspensePlaceholder-test.internal.js index 21637258449ce..de8c76e9e1983 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspensePlaceholder-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspensePlaceholder-test.internal.js @@ -43,7 +43,7 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) { cache = ReactCache.createCache(invalidateCache); } invalidateCache(); - TextResource = ReactCache.createResource(([text, ms = 0]) => { + TextResource = ReactCache.unstable_createResource(([text, ms = 0]) => { let listeners = null; let status = 'pending'; let value = null; diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js b/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js index b36a9a70a4151..0acce64d23a6b 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js @@ -32,7 +32,7 @@ describe('ReactSuspenseWithNoopRenderer', () => { cache = ReactCache.createCache(invalidateCache); } invalidateCache(); - TextResource = ReactCache.createResource(([text, ms = 0]) => { + TextResource = ReactCache.unstable_createResource(([text, ms = 0]) => { return new Promise((resolve, reject) => setTimeout(() => { if (textResourceShouldFail) { diff --git a/packages/react/src/__tests__/ReactProfiler-test.internal.js b/packages/react/src/__tests__/ReactProfiler-test.internal.js index 85b4cb2d50e8a..8a47868a6ac4c 100644 --- a/packages/react/src/__tests__/ReactProfiler-test.internal.js +++ b/packages/react/src/__tests__/ReactProfiler-test.internal.js @@ -2176,7 +2176,7 @@ describe('Profiler', () => { resourcePromise = null; - TextResource = ReactCache.createResource(([text, ms = 0]) => { + TextResource = ReactCache.unstable_createResource(([text, ms = 0]) => { resourcePromise = new Promise((resolve, reject) => setTimeout(() => { yieldForRenderer(`Promise resolved [${text}]`); diff --git a/packages/react/src/__tests__/ReactProfilerDOM-test.internal.js b/packages/react/src/__tests__/ReactProfilerDOM-test.internal.js index f63cfab515aaf..89604f2226951 100644 --- a/packages/react/src/__tests__/ReactProfilerDOM-test.internal.js +++ b/packages/react/src/__tests__/ReactProfilerDOM-test.internal.js @@ -85,7 +85,7 @@ describe('ProfilerDOM', () => { resourcePromise = null; - TextResource = ReactCache.createResource(([text, ms = 0]) => { + TextResource = ReactCache.unstable_createResource(([text, ms = 0]) => { resourcePromise = new Promise( SchedulerTracing.unstable_wrap((resolve, reject) => { setTimeout( diff --git a/scripts/jest/setupTests.js b/scripts/jest/setupTests.js index 38a5cd7027182..285f2adc898c1 100644 --- a/scripts/jest/setupTests.js +++ b/scripts/jest/setupTests.js @@ -48,12 +48,12 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) { ...require('./matchers/interactionTracing'), ...require('./matchers/toWarnDev'), - toFlushWithoutYielding: JestReact.toFlushWithoutYielding, - toFlushAndYield: JestReact.toFlushAndYield, - toFlushAndYieldThrough: JestReact.toFlushAndYieldThrough, - toHaveYielded: JestReact.toHaveYielded, - toFlushAndThrow: JestReact.toFlushAndThrow, - toMatchRenderedOutput: JestReact.toMatchRenderedOutput, + toFlushWithoutYielding: JestReact.unstable_toFlushWithoutYielding, + toFlushAndYield: JestReact.unstable_toFlushAndYield, + toFlushAndYieldThrough: JestReact.unstable_toFlushAndYieldThrough, + toHaveYielded: JestReact.unstable_toHaveYielded, + toFlushAndThrow: JestReact.unstable_toFlushAndThrow, + toMatchRenderedOutput: JestReact.unstable_toMatchRenderedOutput, }); // We have a Babel transform that inserts guards against infinite loops. diff --git a/scripts/jest/spec-equivalence-reporter/setupTests.js b/scripts/jest/spec-equivalence-reporter/setupTests.js index 9b5292bb06950..4b8e1d16faded 100644 --- a/scripts/jest/spec-equivalence-reporter/setupTests.js +++ b/scripts/jest/spec-equivalence-reporter/setupTests.js @@ -50,12 +50,12 @@ expect.extend({ ...require('../matchers/interactionTracing'), ...require('../matchers/toWarnDev'), - toFlushWithoutYielding: JestReact.toFlushWithoutYielding, - toFlushAndYield: JestReact.toFlushAndYield, - toFlushAndYieldThrough: JestReact.toFlushAndYieldThrough, - toHaveYielded: JestReact.toHaveYielded, - toFlushAndThrow: JestReact.toFlushAndThrow, - toMatchRenderedOutput: JestReact.toMatchRenderedOutput, + toFlushWithoutYielding: JestReact.unstable_toFlushWithoutYielding, + toFlushAndYield: JestReact.unstable_toFlushAndYield, + toFlushAndYieldThrough: JestReact.unstable_toFlushAndYieldThrough, + toHaveYielded: JestReact.unstable_toHaveYielded, + toFlushAndThrow: JestReact.unstable_toFlushAndThrow, + toMatchRenderedOutput: JestReact.unstable_toMatchRenderedOutput, }); beforeEach(() => (numExpectations = 0));