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

Fix TypeError in shouldSkipBundle During yarn build-for-devtools-dev and yarn build-for-devtools-prod Commands #29906

Merged
merged 2 commits into from
Jun 20, 2024

Conversation

nakjun12
Copy link
Contributor

Summary

Fix bundle type filtering logic to correctly handle array input in argv.type and use some with includes for accurate filtering. This addresses a TypeError encountered during yarn build-for-devtools-prod and yarn build-for-devtools-dev commands.

Motivation

The current implementation of the shouldSkipBundle function in scripts/rollup/build.js has two issues:

  1. Incorrect array handling in parseRequestedNames(#29613):

    The function incorrectly wraps the argv.type value in an additional array when it's already an array. This leads to a TypeError: names[i].split is not a function when parseRequestedNames attempts to split the nested array, as seen in this error message:

    C:\Users\Administrator\Documents\새 폴더\react\scripts\rollup\build.js:76
        let splitNames = names[i].split(',');
                            ^
    TypeError: names[i].split is not a function
    

    This PR fixes this by correctly handling both string and array inputs in argv.type:

    - const requestedBundleTypes = argv.type
    -   ? parseRequestedNames([argv.type], 'uppercase')
    + const argvType = Array.isArray(argv.type) ? argv.type : [argv.type];
    + const requestedBundleTypes = argv.type
    +   ? parseRequestedNames(argvType, 'uppercase')
  2. Inaccurate filtering logic in shouldSkipBundle(#29614):

    The function uses Array.prototype.every with indexOf to check if all requested bundle types are missing in the current bundle type. However, when multiple bundle types are requested (e.g., ['NODE', 'NODE_DEV']), the function should skip a bundle only if none of the requested types are present. The current implementation incorrectly allows bundles that match any of the requested types.

    To illustrate, consider the following example output:

    requestedBundleTypes [ 'NODE', 'NODE_DEV' ]
    bundleType NODE_DEV
    isAskingForDifferentType false
    
    requestedBundleTypes [ 'NODE', 'NODE_DEV' ]
    bundleType NODE_PROD
    isAskingForDifferentType false  // Incorrect behavior
    

    In this case, even though the bundle type is NODE_PROD and doesn't include NODE_DEV, the bundle is not skipped due to the incorrect logic.

    This PR fixes this by replacing every with some and using includes for a more accurate check:

    - const isAskingForDifferentType = requestedBundleTypes.every(
    -   requestedType => bundleType.indexOf(requestedType) === -1
    - );
    + const isAskingForDifferentType = requestedBundleTypes.some(
    +   requestedType => !bundleType.includes(requestedType)
    + );

    This ensures that the bundle is skipped only if none of the requested types are found in the bundleType.

This PR addresses both of these issues to ensure correct bundle type filtering in various build scenarios.

How did you test this change?

  1. Verification of requestedBundleTypes usage in shouldSkipBundle:

    • I manually tested the following scenarios:
      • yarn build: Verified that requestedBundleTypes remains an empty array, as expected.
      • yarn build-for-devtools: Confirmed that requestedBundleTypes is correctly set to ['NODE'], as in the original implementation.
      • yarn build-for-devtools-dev: This previously failed due to the error. After the fix, I confirmed that requestedBundleTypes is now correctly passed as ['NODE', 'NODE_DEV'].
  2. Debugging of filtering logic in shouldSkipBundle:

    • I added the following logging statements to the shouldSkipBundle function to observe its behavior during the build process:

      console.log('requestedBundleTypes', requestedBundleTypes);
      console.log('bundleType', bundleType);
      console.log('isAskingForDifferentType', isAskingForDifferentType);
    • By analyzing the log output, I confirmed that the filtering logic now correctly identifies when a bundle should be skipped based on the requested types. This allowed me to verify that the fix enables building specific target bundles as intended.

Copy link

vercel bot commented Jun 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 15, 2024 9:59am

@react-sizebot
Copy link

Comparing: f14d7f0...1936873

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.js = 6.66 kB 6.66 kB +0.11% 1.82 kB 1.82 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 497.93 kB 497.93 kB = 89.26 kB 89.26 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.67 kB 6.67 kB +0.05% 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 502.75 kB 502.75 kB = 89.96 kB 89.96 kB
facebook-www/ReactDOM-prod.classic.js = 597.17 kB 597.17 kB = 105.33 kB 105.33 kB
facebook-www/ReactDOM-prod.modern.js = 571.52 kB 571.52 kB = 101.27 kB 101.27 kB
test_utils/ReactAllWarnings.js Deleted 62.88 kB 0.00 kB Deleted 15.69 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
test_utils/ReactAllWarnings.js Deleted 62.88 kB 0.00 kB Deleted 15.69 kB 0.00 kB

Generated by 🚫 dangerJS against 1936873

Copy link
Contributor

@hoxyq hoxyq left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for fixing this!

@hoxyq hoxyq merged commit 395e2fc into facebook:main Jun 20, 2024
44 checks passed
@nakjun12 nakjun12 changed the title [chore] Fix TypeError in shouldSkipBundle During yarn build-for-devtools-dev and yarn build-for-devtools-prod Commands Fix TypeError in shouldSkipBundle During yarn build-for-devtools-dev and yarn build-for-devtools-prod Commands Jul 12, 2024
unstubbable added a commit to unstubbable/react that referenced this pull request Jul 30, 2024
The following bundles were missing so that the flight fixture could not
be started after running `yarn build-for-flight-dev` on a fresh clone:

- `react-server-dom-webpack-node-loader.production.js` (requires `ESM_PROD`)
- `react-server-dom-webpack-plugin.js` (requires `NODE_ES2015`)
- `react-dom.react-server.development.js`
- `react.react-server.development.js`

Since we now need to specify a list of bundle types, we had to fix the
`shouldSkipBundle` function, which apparently was broken in facebook#29906.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants