Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions fixtures/blocks/src/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,18 @@
import React, {
useReducer,
useEffect,
unstable_useTransition as useTransition,
useTransition,
useCallback,
useMemo,
Suspense,
unstable_useCacheRefresh as useCacheRefresh,
unstable_Cache as Cache,
} from 'react';
import {createCache, CacheProvider} from 'react/unstable-cache';
import {RouterProvider} from './client/RouterContext';
// TODO: can't really import a server component on the client.
import App from './server/App';

const initialUrl = window.location.pathname;
const initialState = {
// TODO: use this for invalidation.
cache: createCache(),
url: initialUrl,
pendingUrl: initialUrl,
root: <App route={initialUrl} />,
};

function reducer(state, action) {
switch (action.type) {
Expand All @@ -48,10 +42,14 @@ function reducer(state, action) {
}

function Router() {
const initialState = {
url: initialUrl,
pendingUrl: initialUrl,
root: <App route={initialUrl} />,
};
const [state, dispatch] = useReducer(reducer, initialState);
const [startTransition, isPending] = useTransition({
timeoutMs: 1500,
});
const [isPending, startTransition] = useTransition();
const refresh = useCacheRefresh();

useEffect(() => {
document.body.style.cursor = isPending ? 'wait' : '';
Expand All @@ -62,6 +60,7 @@ function Router() {
startTransition(() => {
// TODO: Here, There, and Everywhere.
// TODO: Instant Transitions, somehow.
refresh();
dispatch({
type: 'completeNavigation',
root: <App route={url} />,
Expand All @@ -73,7 +72,7 @@ function Router() {
url,
});
},
[startTransition]
[startTransition, refresh]
);

useEffect(() => {
Expand All @@ -95,9 +94,9 @@ function Router() {

return (
<Suspense fallback={<h2>Loading...</h2>}>
<CacheProvider value={state.cache}>
<Cache>
<RouterProvider value={routeContext}>{state.root}</RouterProvider>
</CacheProvider>
</Cache>
</Suspense>
);
}
Expand Down
2 changes: 1 addition & 1 deletion fixtures/blocks/src/server/PostList.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/* eslint-disable import/first */

import * as React from 'react';
import {Suspense, unstable_SuspenseList as SuspenseList} from 'react';
import {Suspense, SuspenseList} from 'react';
import {preload} from 'react-fetch';
import PostGlimmer from './PostGlimmer';
import Post from './Post';
Expand Down