98
jest.restoreAllMocks();
99
});
100
101
+ function createServerContext(globalName, defaultValue, withStack) {
102
+ let ctx;
103
+ expect(() => {
104
+ ctx = React.createServerContext(globalName, defaultValue);
105
+ }).toErrorDev(
106
+ 'Server Context is deprecated and will soon be removed. ' +
107
+ 'It was never documented and we have found it not to be useful ' +
108
+ 'enough to warrant the downside it imposes on all apps.',
109
+ {withoutStack: !withStack},
110
+ );
111
+ return ctx;
112
+ }
113
+
114
function clientReference(value) {
115
return Object.defineProperties(
116
function () {
1076
describe('ServerContext', () => {
1077
// @gate enableServerContext
1078
it('supports basic createServerContext usage', async () => {
1066
- const ServerContext = React.createServerContext(
1079
+ const ServerContext = createServerContext(
1080
'ServerContext',
1081
'hello from server',
1082
);
1097
1098
// @gate enableServerContext
1099
it('propagates ServerContext providers in flight', async () => {
1087
- const ServerContext = React.createServerContext(
1088
- 'ServerContext',
1089
- 'default',
1090
- );
1100
+ const ServerContext = createServerContext('ServerContext', 'default');
1101
1102
function Foo() {
1103
return (
1125
1126
// @gate enableServerContext
1127
it('errors if you try passing JSX through ServerContext value', () => {
1118
- const ServerContext = React.createServerContext('ServerContext', {
1128
+ const ServerContext = createServerContext('ServerContext', {
1129
foo: {
1130
bar: <span>hi this is default</span>,
1131
},
1159
1160
// @gate enableServerContext
1161
it('propagates ServerContext and cleans up the providers in flight', async () => {
1152
- const ServerContext = React.createServerContext(
1153
- 'ServerContext',
1154
- 'default',
1155
- );
1162
+ const ServerContext = createServerContext('ServerContext', 'default');
1163
1164
function Foo() {
1165
return (
1203
1204
// @gate enableServerContext
1205
it('propagates ServerContext providers in flight after suspending', async () => {
1199
- const ServerContext = React.createServerContext(
1200
- 'ServerContext',
1201
- 'default',
1202
- );
1206
+ const ServerContext = createServerContext('ServerContext', 'default');
1207
1208
function Foo() {
1209
return (
1258
1259
// @gate enableServerContext
1260
it('serializes ServerContext to client', async () => {
1257
- const ServerContext = React.createServerContext(
1258
- 'ServerContext',
1259
- 'default',
1260
- );
1261
+ const ServerContext = createServerContext('ServerContext', 'default');
1262
1263
function ClientBar() {
1264
Scheduler.log('ClientBar');
1295
expect(ReactNoop).toMatchRenderedOutput(<span>hi this is server</span>);
1296
1297
expect(() => {
1297
- React.createServerContext('ServerContext', 'default');
1298
+ createServerContext('ServerContext', 'default');
1299
}).toThrow('ServerContext: ServerContext already defined');
1300
});
1301
1302
// @gate enableServerContext
1303
it('takes ServerContext from the client for refetching use cases', async () => {
1303
- const ServerContext = React.createServerContext(
1304
- 'ServerContext',
1305
- 'default',
1306
- );
1304
+ const ServerContext = createServerContext('ServerContext', 'default');
1305
function Bar() {
1306
return <span>{React.useContext(ServerContext)}</span>;
1307
}
1321
let ServerContext;
1322
function inlineLazyServerContextInitialization() {
1323
if (!ServerContext) {
1326
- ServerContext = React.createServerContext('ServerContext', 'default');
1324
+ ServerContext = createServerContext('ServerContext', 'default');
1325
}
1326
return ServerContext;
1327
}
1329
let ClientContext;
1330
function inlineContextInitialization() {
1331
if (!ClientContext) {
1334
- ClientContext = React.createServerContext('ServerContext', 'default');
1332
+ ClientContext = createServerContext('ServerContext', 'default', true);
1333
}
1334
return ClientContext;
1335
}