Skip to content

Commit 0151d7e

Browse files
[Blocks] fix broken fixture ServerComponent app
1 parent 4df10c5 commit 0151d7e

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

fixtures/blocks/src/Router.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,18 @@
88
import React, {
99
useReducer,
1010
useEffect,
11-
unstable_useTransition as useTransition,
11+
useTransition,
1212
useCallback,
1313
useMemo,
1414
Suspense,
15+
unstable_useCacheRefresh as useCacheRefresh,
16+
unstable_Cache as Cache,
1517
} from 'react';
16-
import {createCache, CacheProvider} from 'react/unstable-cache';
1718
import {RouterProvider} from './client/RouterContext';
1819
// TODO: can't really import a server component on the client.
1920
import App from './server/App';
2021

2122
const initialUrl = window.location.pathname;
22-
const initialState = {
23-
// TODO: use this for invalidation.
24-
cache: createCache(),
25-
url: initialUrl,
26-
pendingUrl: initialUrl,
27-
root: <App route={initialUrl} />,
28-
};
2923

3024
function reducer(state, action) {
3125
switch (action.type) {
@@ -48,10 +42,14 @@ function reducer(state, action) {
4842
}
4943

5044
function Router() {
45+
const initialState = {
46+
url: initialUrl,
47+
pendingUrl: initialUrl,
48+
root: <App route={initialUrl} />,
49+
};
5150
const [state, dispatch] = useReducer(reducer, initialState);
52-
const [startTransition, isPending] = useTransition({
53-
timeoutMs: 1500,
54-
});
51+
const [isPending, startTransition] = useTransition();
52+
const refresh = useCacheRefresh();
5553

5654
useEffect(() => {
5755
document.body.style.cursor = isPending ? 'wait' : '';
@@ -62,6 +60,7 @@ function Router() {
6260
startTransition(() => {
6361
// TODO: Here, There, and Everywhere.
6462
// TODO: Instant Transitions, somehow.
63+
refresh();
6564
dispatch({
6665
type: 'completeNavigation',
6766
root: <App route={url} />,
@@ -73,7 +72,7 @@ function Router() {
7372
url,
7473
});
7574
},
76-
[startTransition]
75+
[startTransition, refresh]
7776
);
7877

7978
useEffect(() => {
@@ -95,9 +94,9 @@ function Router() {
9594

9695
return (
9796
<Suspense fallback={<h2>Loading...</h2>}>
98-
<CacheProvider value={state.cache}>
97+
<Cache>
9998
<RouterProvider value={routeContext}>{state.root}</RouterProvider>
100-
</CacheProvider>
99+
</Cache>
101100
</Suspense>
102101
);
103102
}

fixtures/blocks/src/server/PostList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/* eslint-disable import/first */
88

99
import * as React from 'react';
10-
import {Suspense, unstable_SuspenseList as SuspenseList} from 'react';
10+
import {Suspense, SuspenseList} from 'react';
1111
import {preload} from 'react-fetch';
1212
import PostGlimmer from './PostGlimmer';
1313
import Post from './Post';

0 commit comments

Comments
 (0)