Skip to content

Commit

Permalink
fix: allow suspense hydration
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Mar 5, 2021
1 parent 8144a9f commit d200d5e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = [
{
path: ['dist/es2015/entrypoints/index.js', 'dist/es2015/entrypoints/boot.js'],
ignore: ['tslib'],
limit: '4.1 KB',
limit: '4.2 KB',
},
{
path: 'dist/es2015/entrypoints/index.js',
Expand Down
6 changes: 3 additions & 3 deletions .size.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
{
"name": "dist/es2015/entrypoints/index.js, dist/es2015/entrypoints/boot.js",
"passed": true,
"size": 4187
"size": 4217
},
{
"name": "dist/es2015/entrypoints/index.js",
"passed": true,
"size": 3817
"size": 3852
},
{
"name": "dist/es2015/entrypoints/boot.js",
"passed": true,
"size": 1923
"size": 1938
}
]
4 changes: 2 additions & 2 deletions src/entrypoints/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { drainHydrateMarks, printDrainHydrateMarks } from '../loadable/marks';
import { createLoadableStream } from '../loadable/stream';
import { getLoadableTrackerCallback } from '../trackers/globalTracker';
import { createLoadableTransformer } from '../transformers/loadableTransformer';
import { Stream } from '../types';
import { Stream as ImportedStreamTracker } from '../types';
import { ImportedStream } from '../ui/context';

export {
Expand All @@ -17,5 +17,5 @@ export {
getLoadableTrackerCallback,
getMarkedChunks,
getMarkedFileNames,
Stream,
ImportedStreamTracker,
};
3 changes: 2 additions & 1 deletion src/ui/LazyBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const LazyClientBoundary: React.FC<{
}> = ({ children, fallback }) => (
<React.Suspense
// we keep fallback null during hydration as it is expected behavior for "ssr-ed" Suspense blocks - they should not "fallback"
fallback={useIsClientPhase() ? fallback : null}
// see https://github.com/sebmarkbage/react/blob/185700696ebbe737c99bd6c4b678d5f2a923bd29/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js#L668-L682
fallback={useIsClientPhase() ? fallback : (undefined as any)}
>
{children}
</React.Suspense>
Expand Down
8 changes: 3 additions & 5 deletions src/ui/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import * as React from 'react';
import { defaultStream } from '../loadable/stream';
import { Stream } from '../types';

interface TakeProps {
stream: Stream;
}

export const streamContext = React.createContext(defaultStream);

/**
* SSR. Tracker for used marks
*/
export const ImportedStream: React.FC<TakeProps> = ({ stream, children, ...props }) => {
export const ImportedStream: React.FC<{
stream: Stream;
}> = ({ stream, children, ...props }) => {
if (process.env.NODE_ENV !== 'development') {
if ('takeUID' in props) {
throw new Error('react-imported-component: `takeUID` was replaced by `stream`.');
Expand Down

0 comments on commit d200d5e

Please sign in to comment.