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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add entry startup to fix async script chunk loading #2966

Merged
merged 1 commit into from
May 4, 2023

Conversation

underfin
Copy link
Collaborator

@underfin underfin commented Apr 27, 2023

Related issue (if exists)

close #2775

Summary

  • fix async script chunk loading, avoid loading module error
  • fix chunk loaded runtime inject
  • fix some runtime to es5

馃 Generated by Copilot at d86865c

This pull request adds a new library plugin for exporting properties, improves the code generation and performance of the JavaScript and runtime plugins, and fixes the async script chunk loading issue. It also refactors some code, updates some imports, and adds a changeset file.

Walkthrough

馃 Generated by Copilot at d86865c

  • Add a new plugin for assigning the exports to a property of the global object (F8, link)
  • Modify the render_bootstrap function in the rspack_binding_options crate to include the new plugin for the umd, umd2, amd, and amd-require library types (link, link)
  • Add a new field, source, to the RenderStartupArgs struct in the rspack_core crate to pass the startup code generated by the previous plugins to the next plugins (link, link, link, link, link, link)
  • Modify the render_startup function in the plugin_driver.rs file in the rspack_core crate to clone and pass the source code to each plugin and return the final source code (link)
  • Add a new constant, ENTRY_MODULE_ID, to the runtime_globals.rs file in the rspack_core crate to store the module id of the entry module of a chunk (link)
  • Modify the get_runtime_global function in the runtime_globals.rs file in the rspack_core crate to handle the case of the ENTRY_MODULE_ID constant and return the corresponding code (link)
  • Remove the generate_chunk_entry_code function from the runtime.rs file in the rspack_plugin_javascript crate, as it is replaced by the generate_entry_startup function in the helpers.rs file in the rspack_plugin_runtime crate (link)
  • Split the render_bootstrap function in the plugin.rs file in the rspack_plugin_javascript crate into two parts, one that returns the header code and one that returns the startup code, and add a parameter, chunk_ukey, to the function (link, link)
  • Move the code for exposing the module execution interceptor to the header part of the render_bootstrap function in the plugin.rs file in the rspack_plugin_javascript crate, and add a condition to check if the INTERCEPT_MODULE_EXECUTION runtime requirement is present (link)
  • Replace the call to the generate_chunk_entry_code function with a call to the generate_entry_startup function in the render_chunk function in the plugin.rs file in the rspack_plugin_javascript crate, and pass the startup code to the render_startup hook of the plugins (link)
  • Add a condition to check if the RETURN_EXPORTS_FROM_RUNTIME runtime requirement is present in the render_chunk function in the plugin.rs file in the rspack_plugin_javascript crate, and move the code for returning the exports to the end of the function (link)
  • Append the source code passed by the RenderStartupArgs struct to the output source in the render_startup function in the assign_library_plugin.rs and module_library_plugin.rs files in the rspack_plugin_library crate, so that the plugins can preserve the startup code generated by the previous plugins (link, link)
  • Add the OnChunkLoadedRuntimeModule to the chunk if the ON_CHUNKS_LOADED runtime requirement is present in the apply function in the basic_runtime_requirements.rs file in the rspack_plugin_runtime crate (link)
  • Remove the block of code that adds the OnChunkLoadedRuntimeModule to the chunk from the apply function in the lib.rs file in the rspack_plugin_runtime crate, as it is handled by the basic_runtime_requirements.rs file (link)
  • Replace the call to the get_runtime_chunk_path function with a call to the get_relative_path function in the render_chunk function in the common_js_chunk_format.rs and module_chunk_format.rs files in the rspack_plugin_runtime crate, and add a new variable, base_chunk_output_name, to store the output name of the base chunk (link, link, link)
  • Rename the get_runtime_chunk_path function to get_runtime_chunk_output_name in the helpers.rs file in the rspack_plugin_runtime crate, and remove the ./ prefix from the output name (link)
  • Replace the call to the render method of the chunk_filename field of the output options with a call to the get_chunk_output_name function in the get_runtime_chunk_output_name function in the helpers.rs file in the rspack_plugin_runtime crate, and add the get_chunk_output_name function to the same file (link)
  • Change the type of the exclude_chunk2 parameter from a reference to a ChunkUkey to an option of a reference to a ChunkUkey in the get_all_chunks function in the helpers.rs file in the rspack_plugin_runtime crate, and add a condition to check if the parameter is Some (link, link, link)
  • Move the stringify_chunks_to_array and stringify_array functions from the utils.rs file in the rspack_plugin_runtime crate to the runtime.rs file in the rspack_plugin_javascript crate, as they are more related to the JavaScript plugin than the runtime plugin (link, link, link)
  • Move the stringify_chunks function from the utils.rs file in the rspack_plugin_runtime crate to the mod.rs file in the same crate, as it is more related to the runtime plugin than the JavaScript plugin (link)
  • Add a markdown file to the .changeset folder, which is used by the changesets tool to generate changelogs and version bumps for the packages in the repository (link)

@changeset-bot
Copy link

changeset-bot bot commented Apr 27, 2023

馃 Changeset detected

Latest commit: a47f329

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@rspack/core Patch
@rspack/cli Patch
@rspack/dev-middleware Patch
@rspack/dev-server Patch
@rspack/plugin-html Patch
webpack-test Patch
benchmarkcase-rspack-react-refresh Patch
@rspack/postcss-loader Patch
@rspack/dev-client Patch
@rspack/plugin-minify Patch
@rspack/plugin-node-polyfill Patch
@rspack/binding-darwin-arm64 Patch
@rspack/binding-darwin-x64 Patch
@rspack/binding-linux-x64-gnu Patch
@rspack/binding-win32-x64-msvc Patch
@rspack/binding Patch
@rspack/fs Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@underfin underfin marked this pull request as draft April 27, 2023 12:31
@underfin underfin force-pushed the entry_startup branch 2 times, most recently from 50c1377 to 42ba0d3 Compare April 28, 2023 08:13
@underfin underfin marked this pull request as ready for review April 28, 2023 08:27
@underfin underfin added this pull request to the merge queue May 4, 2023
Merged via the queue into main with commit c567571 May 4, 2023
16 checks passed
@underfin underfin deleted the entry_startup branch May 4, 2023 03:39
This was referenced May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

undefined factory : xxx_module in stream ssr.
2 participants