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

Add IIFE bundle for SSR instruction streaming runtime #25459

Closed

Conversation

mofeiZ
Copy link
Contributor

@mofeiZ mofeiZ commented Oct 10, 2022

(Loosely followed #25436 to find what changes to make)

We're adding an option to Fizz to support an alternate output format that doesn't rely on inline script tags (see #25437). Part of this change involves publishing a minimal client runtime to observe and process SSR instructions.

This PR adds a new bundle "instruction-streaming-runtime", which will be compiled to an IIFE.

  • instruction-streaming-runtime will be published by React and be a standalone script that installs this minimal client runtime
  • [ServerRenderer] Add option to send instructions as data attributes #25437 will require a runtimeSrc param if the enableFizzNoScriptExecution is toggled (in SSR entrypoints params). We expect clients to pass a url to the instruction-streaming-runtime bundle here.

@mofeiZ mofeiZ requested a review from acdlite October 10, 2022 22:16
@facebook-github-bot facebook-github-bot added the React Core Team Opened by a member of the React Core Team label Oct 10, 2022
@mofeiZ mofeiZ requested review from gnoff and sebmarkbage October 10, 2022 22:16
@mofeiZ mofeiZ force-pushed the add-bundle-external-streaming-runtime branch from 00e84f0 to 513a715 Compare October 10, 2022 22:57
@sizebot
Copy link

sizebot commented Oct 10, 2022

Comparing: aa9988e...513a715

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 135.47 kB 135.47 kB = 43.44 kB 43.44 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 148.01 kB 148.01 kB = 47.33 kB 47.33 kB
facebook-www/ReactDOM-prod.classic.js = 492.51 kB 492.51 kB = 87.52 kB 87.52 kB
facebook-www/ReactDOM-prod.modern.js = 477.80 kB 477.80 kB = 85.29 kB 85.29 kB
facebook-www/ReactDOMForked-prod.classic.js = 492.51 kB 492.51 kB = 87.52 kB 87.52 kB
facebook-www/ReactDOMInstructionStreamingRuntime-dev.modern.js +∞% 0.00 kB 0.58 kB +∞% 0.00 kB 0.39 kB
facebook-www/ReactDOMInstructionStreamingRuntime-prod.modern.js +∞% 0.00 kB 0.34 kB +∞% 0.00 kB 0.25 kB
oss-experimental/react-dom/iife/instruction-streaming-runtime.development.js +∞% 0.00 kB 0.51 kB +∞% 0.00 kB 0.35 kB
oss-experimental/react-dom/iife/instruction-streaming-runtime.production.min.js +∞% 0.00 kB 0.33 kB +∞% 0.00 kB 0.24 kB
oss-stable-semver/react-dom/static.browser.js +∞% 0.00 kB 0.23 kB +∞% 0.00 kB 0.16 kB
oss-stable-semver/react-dom/static.js +∞% 0.00 kB 0.06 kB +∞% 0.00 kB 0.08 kB
oss-stable-semver/react-dom/static.node.js +∞% 0.00 kB 0.22 kB +∞% 0.00 kB 0.16 kB
oss-stable-semver/react-dom/unstable_testing.js +∞% 0.00 kB 1.40 kB +∞% 0.00 kB 0.67 kB
oss-stable-semver/react/unstable-cache.js +∞% 0.00 kB 0.22 kB +∞% 0.00 kB 0.16 kB
oss-stable/react-dom/static.browser.js +∞% 0.00 kB 0.23 kB +∞% 0.00 kB 0.16 kB
oss-stable/react-dom/static.js +∞% 0.00 kB 0.06 kB +∞% 0.00 kB 0.08 kB
oss-stable/react-dom/static.node.js +∞% 0.00 kB 0.22 kB +∞% 0.00 kB 0.16 kB
oss-stable/react-dom/unstable_testing.js +∞% 0.00 kB 1.40 kB +∞% 0.00 kB 0.67 kB
oss-stable/react/unstable-cache.js +∞% 0.00 kB 0.22 kB +∞% 0.00 kB 0.16 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
facebook-www/ReactDOMInstructionStreamingRuntime-dev.modern.js +∞% 0.00 kB 0.58 kB +∞% 0.00 kB 0.39 kB
facebook-www/ReactDOMInstructionStreamingRuntime-prod.modern.js +∞% 0.00 kB 0.34 kB +∞% 0.00 kB 0.25 kB
oss-experimental/react-dom/iife/instruction-streaming-runtime.development.js +∞% 0.00 kB 0.51 kB +∞% 0.00 kB 0.35 kB
oss-experimental/react-dom/iife/instruction-streaming-runtime.production.min.js +∞% 0.00 kB 0.33 kB +∞% 0.00 kB 0.24 kB
oss-stable-semver/react-dom/static.browser.js +∞% 0.00 kB 0.23 kB +∞% 0.00 kB 0.16 kB
oss-stable-semver/react-dom/static.js +∞% 0.00 kB 0.06 kB +∞% 0.00 kB 0.08 kB
oss-stable-semver/react-dom/static.node.js +∞% 0.00 kB 0.22 kB +∞% 0.00 kB 0.16 kB
oss-stable-semver/react-dom/unstable_testing.js +∞% 0.00 kB 1.40 kB +∞% 0.00 kB 0.67 kB
oss-stable-semver/react/unstable-cache.js +∞% 0.00 kB 0.22 kB +∞% 0.00 kB 0.16 kB
oss-stable/react-dom/static.browser.js +∞% 0.00 kB 0.23 kB +∞% 0.00 kB 0.16 kB
oss-stable/react-dom/static.js +∞% 0.00 kB 0.06 kB +∞% 0.00 kB 0.08 kB
oss-stable/react-dom/static.node.js +∞% 0.00 kB 0.22 kB +∞% 0.00 kB 0.16 kB
oss-stable/react-dom/unstable_testing.js +∞% 0.00 kB 1.40 kB +∞% 0.00 kB 0.67 kB
oss-stable/react/unstable-cache.js +∞% 0.00 kB 0.22 kB +∞% 0.00 kB 0.16 kB

Generated by 🚫 dangerJS against 513a715

@@ -224,6 +228,11 @@ function getFormat(bundleType) {
return `cjs`;
case NODE_ESM:
return `es`;
case IIFE_DEV:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's worth having a dev build of this. It doesn't have any warnings or anything. Let's just do prod only.

@@ -1018,13 +1041,17 @@ function getOriginalFilename(bundle, bundleType) {
return `${name}.production.min.js`;
case NODE_PROFILING:
return `${name}.profiling.min.js`;
case IIFE_PROD:
return `${name}.production.min.js`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here, I don't think we should bother with the .production.min.js stuff. We do that in our packages that are consumed by a bundler (like ES Modules or Common JS) but in this case there is no bundler, Fizz is going to inject this directly.

So let's just output the exact filename.

@@ -88,6 +94,9 @@ function getBundleOutputPath(bundleType, filename, packageName) {
default:
throw new Error('Unknown RN package.');
}
case IIFE_DEV:
case IIFE_PROD:
return `build/node_modules/${packageName}/iife/${filename}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar here: let's remove the iife subdirectory and place it directly at the top level.

${source}`;
},

[IIFE_DEV](source, globalName, filename, moduleType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can skip this. Remember these files are going to get sent straight to the browser with no post-processing by a bundler or minifier. Don't want the extra bytes.

? [IIFE_DEV, IIFE_PROD, FB_IIFE_DEV, FB_IIFE_PROD]
: [],
moduleType: RENDERER,
entry: 'react-dom/instruction-streaming-runtime',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably prefix this with unstable- for now

@acdlite
Copy link
Collaborator

acdlite commented Oct 15, 2022

Landed with a slightly modified approach in 54f0e0f

@acdlite acdlite closed this Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants