Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CPU performance in RSC #1452

Merged
merged 2 commits into from
Jun 7, 2022
Merged
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
5 changes: 5 additions & 0 deletions .changeset/five-cougars-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen': patch
---

Reduce CPU consumption when rendering React Server Components.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* LICENSE file in the root directory of this source tree.
*/

import { useState } from 'react';
import React from 'react';

// Store of components discovered during RSC to load
// them later when consuming the response in SSR.
Expand All @@ -21,12 +21,8 @@ var STRING_SIZE_LIMIT = 64;
var FN_RSC_ERROR = 'Functions exported from client components cannot be called or used as constructors from a server component.'; // TODO what's a better way to detect Flight runtime?

function isRsc() {
try {
useState();
return false;
} catch (error) {
return error.message.endsWith('Server Components.');
}
// This method is only available during RSC
return !!React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current.getCacheForType;
}

function createModuleReference(id, value, name, isDefault) {
Expand Down