Skip to content

Commit

Permalink
Add highWaterMark default to React Flight readable (#1451)
Browse files Browse the repository at this point in the history
  • Loading branch information
frandiox committed Jun 7, 2022
1 parent cd354d3 commit 47ae1f5
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 43 deletions.
Expand Up @@ -293,6 +293,7 @@ async function proxyClientComponent(filepath, src) {
var DEFAULT_EXPORT = 'default'; // Modify the import ID to avoid infinite wraps

var importFrom = filepath + "?no-proxy";
await esModuleLexer.init;

if (!src) {
src = await fs.promises.readFile(filepath, 'utf-8');
Expand Down Expand Up @@ -430,7 +431,7 @@ function isDirectImportInServer(currentMod, originalMod) {
}

function resolveModPath(modPath, dirname, retryExtension) {
var absolutePath;
var absolutePath = '';

try {
absolutePath = modPath.startsWith('.') ? vite.normalizePath(path.resolve(dirname, modPath)) : modPath;
Expand Down
Expand Up @@ -1017,13 +1017,13 @@ function attemptResolveElement(type, key, ref, props) {
throw new Error('Refs cannot be used in server components, nor passed to client components.');
}

if (type != null && isModuleReference(type)) {
// This is a reference to a client component.
return [REACT_ELEMENT_TYPE, type, key, props];
}

if (typeof type === 'function') {
// This is a server-side component.
if (isModuleReference(type)) {
// This is a reference to a client component.
return [REACT_ELEMENT_TYPE, type, key, props];
} // This is a server-side component.


return type(props);
} else if (typeof type === 'string') {
// This is a host element. E.g. HTML.
Expand All @@ -1041,6 +1041,11 @@ function attemptResolveElement(type, key, ref, props) {

return [REACT_ELEMENT_TYPE, type, key, props];
} else if (type != null && typeof type === 'object') {
if (isModuleReference(type)) {
// This is a reference to a client component.
return [REACT_ELEMENT_TYPE, type, key, props];
}

switch (type.$$typeof) {
case REACT_LAZY_TYPE:
{
Expand Down Expand Up @@ -1445,7 +1450,7 @@ function resolveModelToJSON(request, parent, key, value) {
// Verify that this is a simple plain object.
if (objectName(value) !== 'Object') {
error('Only plain objects can be passed to client components from server components. ' + 'Built-ins like %s are not supported. ' + 'Remove %s from these props: %s', objectName(value), describeKeyForErrorMessage(key), describeObjectForErrorMessage(parent));
} else if (!isSimpleObject(value)) {
} else if (typeof value === 'object' && !isSimpleObject(value)) {
error('Only plain objects can be passed to client components from server components. ' + 'Classes or other objects with methods are not supported. ' + 'Remove %s from these props: %s', describeKeyForErrorMessage(key), describeObjectForErrorMessage(parent, key));
} else if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(value);
Expand Down Expand Up @@ -1754,6 +1759,9 @@ function renderToReadableStream(model, options, context) {
startFlowing(request, controller);
},
cancel: function (reason) {}
}, // $FlowFixMe size() methods are not allowed on byte streams.
{
highWaterMark: 0
});
return stream;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -1083,13 +1083,13 @@ function attemptResolveElement(type, key, ref, props) {
throw new Error('Refs cannot be used in server components, nor passed to client components.');
}

if (type != null && isModuleReference(type)) {
// This is a reference to a client component.
return [REACT_ELEMENT_TYPE, type, key, props];
}

if (typeof type === 'function') {
// This is a server-side component.
if (isModuleReference(type)) {
// This is a reference to a client component.
return [REACT_ELEMENT_TYPE, type, key, props];
} // This is a server-side component.


return type(props);
} else if (typeof type === 'string') {
// This is a host element. E.g. HTML.
Expand All @@ -1107,6 +1107,11 @@ function attemptResolveElement(type, key, ref, props) {

return [REACT_ELEMENT_TYPE, type, key, props];
} else if (type != null && typeof type === 'object') {
if (isModuleReference(type)) {
// This is a reference to a client component.
return [REACT_ELEMENT_TYPE, type, key, props];
}

switch (type.$$typeof) {
case REACT_LAZY_TYPE:
{
Expand Down Expand Up @@ -1511,7 +1516,7 @@ function resolveModelToJSON(request, parent, key, value) {
// Verify that this is a simple plain object.
if (objectName(value) !== 'Object') {
error('Only plain objects can be passed to client components from server components. ' + 'Built-ins like %s are not supported. ' + 'Remove %s from these props: %s', objectName(value), describeKeyForErrorMessage(key), describeObjectForErrorMessage(parent));
} else if (!isSimpleObject(value)) {
} else if (typeof value === 'object' && !isSimpleObject(value)) {
error('Only plain objects can be passed to client components from server components. ' + 'Classes or other objects with methods are not supported. ' + 'Remove %s from these props: %s', describeKeyForErrorMessage(key), describeObjectForErrorMessage(parent, key));
} else if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(value);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -565,13 +565,13 @@ function startReadingFromStream(response, stream) {
}

function createFromReadableStream(stream) {
var response = createResponse$1();
var response = createResponse$1({});
startReadingFromStream(response, stream);
return response;
}

function createFromFetch(promiseForResponse) {
var response = createResponse$1();
var response = createResponse$1({});
promiseForResponse.then(function (r) {
startReadingFromStream(response, r.body);
}, function (e) {
Expand All @@ -581,7 +581,7 @@ function createFromFetch(promiseForResponse) {
}

function createFromXHR(request) {
var response = createResponse$1();
var response = createResponse$1({});
var processedLength = 0;

function progress(e) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -289,6 +289,7 @@ async function proxyClientComponent(filepath, src) {
var DEFAULT_EXPORT = 'default'; // Modify the import ID to avoid infinite wraps

var importFrom = filepath + "?no-proxy";
await init;

if (!src) {
src = await promises.readFile(filepath, 'utf-8');
Expand Down Expand Up @@ -426,7 +427,7 @@ function isDirectImportInServer(currentMod, originalMod) {
}

function resolveModPath(modPath, dirname, retryExtension) {
var absolutePath;
var absolutePath = '';

try {
absolutePath = modPath.startsWith('.') ? normalizePath(path.resolve(dirname, modPath)) : modPath;
Expand Down

0 comments on commit 47ae1f5

Please sign in to comment.