GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor: close written unknown and object escapes without breaking public types by alexander-akait · Pull Request #23126 · webpack/webpack

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Nov 4, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Summary

This follows #23120. It replaces written unknown/object/any escapes with real types wherever the public types and runtime can stay exactly as they are.

Kind Before After
any 52 51
unknown 69 62
object 29 19
Function 1 1
  • WeakMap keys use WeakKey instead of EXPECTED_OBJECT. This covers WeakTupleMap, AssociatedObjectForCache and the identifier caches.
  • cleverMerge caches: the merge and property caches get typed views, the same pattern as the existing ParseCache, and 3 casts go away.
    // before
    /** @type {WeakMap<EXPECTED_OBJECT, WeakMap<EXPECTED_OBJECT, EXPECTED_OBJECT>>} */
    const mergeCache = new WeakMap();
    const prevMerge = /** @type {T & O} */ (innerCache.get(second));
    // after
    const mergeCache = /** @type {MergeCache} */ (new WeakMap());
    const prevMerge = innerCache.get(second);
  • HMR runtime: __webpack_require__ is typed as the full WebpackRequire instead of (id: ModuleId) => unknown.
  • ProfilingPlugin and HotspotsPlugin: the async taps replace the last tuple argument in place, which removes a double cast through unknown[].
  • PrecompiledCheck drops its T = unknown default. Every use passes T, and the interface isn't exported by name.
  • LoaderOptionsPlugin: a redundant LoaderContext<EXPECTED_ANY> & in a cast is removed.

The remaining escapes are public types, such as ExecuteModuleExports, the schema additionalProperties bags, the logger Args, BuildInfo/BuildMeta and the StatsPluginValue overloads. Some are thrown or caught values that really are unknown. Closing them needs a breaking change.

What kind of change does this PR introduce?

refactor

Did you add tests for your changes?

No. The changes are type-only. lint:types-all, the unit tests (including ProfilingPlugin in Chrome) and StatsTestCases pass.

Does this PR introduce a breaking change?

No. The only types.d.ts change is PrecompiledCheck<T = unknown> → PrecompiledCheck<T>, and every use passes a type argument. Runtime behaviour is unchanged.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

n/a

Use of AI

Claude Code wrote the changes in parallel groups and ran the type-coverage tool, type checks and tests. Each change was reviewed against three rules: no any, no unknown swaps, and no workarounds. One group's change was held back because it replaced double casts with a type no value has.


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of callbacks in asynchronous profiling and performance tracking, preserving their position in the original arguments while applying measurement wrappers.
  • Refactor
    • Clarified internal type information used across module loading, caching, and configuration. These updates do not change runtime behavior.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
alexander-akait added 6 commits November 4, 2026 14:12
@alexander-akait
refactor: drop redundant loader context cast in LoaderOptionsPlugin
8652f4e
@alexander-akait
refactor: close unknown spots in HMR runtime, profiling taps and prec…
c39b901
…ompiled checks

- type the HMR runtime's __webpack_require__ as the WebpackRequire it is and
  derive the forwarded require's return and property types from it
- replace the async tap's callback in place instead of popping it, which
  drops the double cast through unknown[] in ProfilingPlugin and HotspotsPlugin
- drop the unused unknown default of PrecompiledCheck
@alexander-akait
refactor: type weak-keyed caches with WeakKey and typed cache views
2fc7834
Close object escapes in cleverMerge, WeakTupleMap, identifier and getResolveOptionsKey. Public types.d.ts is unchanged.
@alexander-akait
Merge branch 'wip/escapes-runtime' into refactor/close-written-escapes
ff15b34
@alexander-akait
Merge branch 'wip/escapes-utils' into refactor/close-written-escapes
805324b
@alexander-akait
chore: regenerate types
7bf5a54
@changeset-bot

changeset-bot Bot commented Nov 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7bf5a54

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added area: loaders Loader execution and loader API (lib/loaders) area: types types.d.ts, JSDoc annotations, hand-maintained declarations area: watch Watching, HMR, lazy compilation (lib/hmr, hot/) labels Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Reports for 7bf5a54, computed by this pull request's own code. Each section updates when its workflow finishes.


Preview package

This PR is packaged and the instant preview of its latest commit is available.

Install it locally:

  • npm
npm i -D webpack@https://pkg.pr.new/webpack@23126
  • yarn
yarn add -D webpack@https://pkg.pr.new/webpack@23126
  • pnpm
pnpm add -D webpack@https://pkg.pr.new/webpack@23126

From Preview package run #11978.


Generated code size

Comparing base (58bbf0f) to head (7bf5a54). Merging this pull request will not change the code webpack generates.

What moved Tests Assets Gzip Raw Test edit
Changed, test untouched 0 0 — — —
Changed, test edited 0 0 — — —
New 0 0 — — —
Deleted 0 0 — — —
Unchanged — 9981 — — —

Read Changed, test untouched first: the test is byte-identical on both sides, so webpack generated the difference. Changed, test edited moved partly because the test did — Test edit is how many bytes the test gained, and a bundle that grew by less is not a regression. New and Deleted are whole files, not deltas — a new asset was created, not grown, so it reads gray (⚪ added) — and adding tests cannot bury a real change. Gzip decides, because that is what users download; raw is the tiebreak, and brotli and zstd are per asset below.

Sample apps

No sample app changed size.

26 unchanged app(s)
App Gzip Gzip change Raw Raw change
library amd 1.38 KiB — 2.68 KiB —
library amd-require 1.38 KiB — 2.67 KiB —
library assign 1.38 KiB — 2.67 KiB —
library assign-properties 1.42 KiB — 2.80 KiB —
library commonjs 1.38 KiB — 2.66 KiB —
library commonjs-module 1.38 KiB — 2.67 KiB —
library commonjs-static 1.55 KiB — 3.54 KiB —
library commonjs2 1.38 KiB — 2.67 KiB —
library global 1.38 KiB — 2.66 KiB —
library jsonp 1.37 KiB — 2.66 KiB —
library module 1.21 KiB — 2.35 KiB —
library self 1.38 KiB — 2.66 KiB —
library system 1.41 KiB — 2.73 KiB —
library this 1.38 KiB — 2.66 KiB —
library umd 1.44 KiB — 2.86 KiB —
library umd2 1.44 KiB — 2.86 KiB —
library var 1.38 KiB — 2.67 KiB —
library window 1.38 KiB — 2.66 KiB —
node-ssr 96.36 KiB — 371.30 KiB —
node-ssr-esm 96.61 KiB — 372.00 KiB —
react-100 32.06 KiB — 150.15 KiB —
react-1k 73.05 KiB — 906.51 KiB —
react-1k-esm 72.54 KiB — 906.44 KiB —
react-5k 190.87 KiB — 4.08 MiB —
webworker 36.15 KiB — 93.71 KiB —
webworker-esm 35.67 KiB — 94.21 KiB —

No asset changed size.

No runtime gained or lost a runtime module.

Built test/configCases with the defaults a user gets, and the apps in test/sizeCoreReports (apps/): 2383 test(s), 9981 asset(s), 104 emitted nothing.

From Generated code size run #6613.


Types Coverage

Typed lines: 99.59% (170144 of 170846)

Kind Base Head Change
any 52 51 🟢 −1
unknown 69 62 🟢 −7
object 29 19 🟢 −10
Function 1 1 —
untyped 134 134 —

any counts EXPECTED_ANY, a written any and the any TypeScript infers where no type is written, such as const map = new Map() or const list = []. object counts EXPECTED_OBJECT and Object, Function counts EXPECTED_FUNCTION. Untyped counts the identifiers whose type is or holds any, wherever it comes from; the any TypeScript's built-in lib writes in its own signatures, such as the replacer of String#replace, is left out, and so is the open fallback beside declared fields, such as KnownBuildInfo & Record<string, any>, though reading a key no field declares is counted.

Changed by this pull request

File Typed lines any unknown object Function untyped
lib/debug/ProfilingPlugin.js 100.00% 0 (🟢 −1)
lib/hmr/HotModuleReplacement.runtime.js 100.00% 2 (🟢 −3) 1
lib/hmr/JavascriptHotModuleReplacement.runtime.js 100.00% 6 (🟢 −1) 2
lib/loaders/LoaderOptionsPlugin.js 100.00% 4 (🟢 −1)
lib/performance/HotspotsPlugin.js 100.00% 0 (🟢 −1)
lib/resolve/getResolveOptionsKey.js 100.00% 4 0 (🟢 −1)
lib/util/WeakTupleMap.js 100.00% 0 (🟢 −3)
lib/util/cleverMerge.js 100.00% 2 (🟢 −5)
lib/util/identifier.js 100.00% 0 (🟢 −1)
lib/util/validateSchema.js 100.00% 0 (🟢 −1)
What the files this pull request changes still have
  • lib/hmr/HotModuleReplacement.runtime.js:9 object
  • lib/hmr/HotModuleReplacement.runtime.js:17 unknown
  • lib/hmr/HotModuleReplacement.runtime.js:17 unknown
  • lib/hmr/JavascriptHotModuleReplacement.runtime.js:10 object
  • lib/hmr/JavascriptHotModuleReplacement.runtime.js:13 unknown
  • lib/hmr/JavascriptHotModuleReplacement.runtime.js:14 unknown
  • lib/hmr/JavascriptHotModuleReplacement.runtime.js:15 object (EXPECTED_OBJECT)
  • lib/hmr/JavascriptHotModuleReplacement.runtime.js:16 unknown
  • lib/hmr/JavascriptHotModuleReplacement.runtime.js:16 unknown
  • lib/hmr/JavascriptHotModuleReplacement.runtime.js:17 unknown
  • lib/hmr/JavascriptHotModuleReplacement.runtime.js:448 unknown
  • lib/loaders/LoaderOptionsPlugin.js:34 any (EXPECTED_ANY)
  • lib/loaders/LoaderOptionsPlugin.js:42 any (EXPECTED_ANY)
  • lib/loaders/LoaderOptionsPlugin.js:50 any (EXPECTED_ANY)
  • lib/loaders/LoaderOptionsPlugin.js:91 any (EXPECTED_ANY)
  • lib/resolve/getResolveOptionsKey.js:24 unknown
  • lib/resolve/getResolveOptionsKey.js:26 unknown
  • lib/resolve/getResolveOptionsKey.js:27 unknown
  • lib/resolve/getResolveOptionsKey.js:40 unknown
  • lib/util/cleverMerge.js:138 object
  • lib/util/cleverMerge.js:138 object
63 file(s) in lib/, hot/ and declarations/ still have an escape hatch, `any` or untyped identifiers
File Typed lines any unknown object Function untyped
declarations/WebpackOptions.ts 99.94% 15 5
lib/Compilation.js 99.75% 5 15
lib/module/NormalModule.js 99.54% 4 1 11
lib/logging/createConsoleLogger.js 99.00% 15
lib/module/NormalModuleFactory.js 99.41% 15
lib/html/HtmlModulesPlugin.js 99.76% 11
lib/javascript/syntax-parser.js 100.00% 10
lib/asset/AssetModulesPlugin.js 99.38% 9
lib/hmr/JavascriptHotModuleReplacement.runtime.js 100.00% 6 (🟢 −1) 2
lib/hmr/lazyCompilationBackend.js 100.00% 7
lib/Compiler.js 100.00% 2 4
lib/javascript/syntax-printer.js 100.00% 1 5
lib/loaders/LoaderPlugin.js 99.42% 6
lib/util/SourceProcessor.js 100.00% 6
lib/MultiCompiler.js 100.00% 5
lib/define/DefinePlugin.js 100.00% 4 1
lib/dependencies/amd/AMDPlugin.js 99.31% 5
lib/serialization/FileMiddleware.js 100.00% 5
lib/dependencies/amd/AMDRuntimeModules.js 95.45% 4
lib/javascript/JavascriptModulesPlugin.js 100.00% 4
lib/loaders/LoaderOptionsPlugin.js 100.00% 4 (🟢 −1)
lib/module/Module.js 100.00% 4
lib/resolve/getResolveOptionsKey.js 100.00% 4 0 (🟢 −1)
lib/serialization/ObjectMiddleware.js 100.00% 4
lib/util/SortableSet.js 100.00% 4
lib/config/normalization.js 99.57% 3
lib/css/syntax-parser.js 100.00% 3
lib/hmr/HotModuleReplacement.runtime.js 100.00% 2 (🟢 −3) 1
lib/html/syntax-parser.js 100.00% 3
lib/javascript/JavascriptParser.js 100.00% 1 2
lib/stats/StatsFactory.js 100.00% 2 1
lib/config/defineConfig.js 100.00% 2
lib/css/syntax.js 100.00% 2
lib/graph/ModuleGraph.js 100.00% 1 1
lib/hmr/HotModuleReplacementPlugin.js 100.00% 1 1
lib/html/syntax.js 100.00% 2
lib/index.js 100.00% 2
lib/loaders/LoaderRunner.js 100.00% 2
lib/module/Parser.js 100.00% 2
lib/node/nodeConsole.js 100.00% 2
lib/resolve/ResolverFactory.js 98.67% 2
lib/rules/BasicEffectRulePlugin.js 93.75% 2
lib/rules/UseEffectRulePlugin.js 99.06% 2
lib/util/cleverMerge.js 100.00% 2 (🟢 −5)
lib/util/implicitTypeLoaderFallback.js 100.00% 2
hot/poll.js 100.00% 1
lib/config/WebpackOptionsApply.js 100.00% 1
lib/config/cli.js 100.00% 1
lib/dependencies/import/ImportParserPlugin.js 100.00% 1
lib/dll/DllReferencePlugin.js 100.00% 1
lib/errors/JSONParseError.js 100.00% 1
lib/errors/NonErrorEmittedError.js 100.00% 1
lib/errors/WebpackError.js 100.00% 1
lib/javascript/syntax.js 100.00% 1
lib/logging/Logger.js 100.00% 1
lib/output/ManifestPlugin.js 100.00% 1
lib/serialization/types.js 100.00% 1
lib/stats/DefaultStatsFactoryPlugin.js 100.00% 1
lib/stats/StatsPrinter.js 100.00% 1
lib/template/Template.js 100.00% 1
lib/util/magicComment.js 100.00% 1
lib/util/makeSerializable.js 100.00% 1
lib/util/terminalColors.js 100.00% 1

From Types Coverage run #2978.


Module loading

How many files a fresh Node.js process loads (require or import) to do each thing below; a change from the pull request's base is marked 🔴 when it grew and 🟢 when it shrank. Every file is startup time, so fewer is better. webpack files are this package's own (lib/, hot/); node_modules files are its dependencies'.

What the process does webpack files node_modules files
require("webpack") 2 0
import "webpack" 2 0
JavaScript syntax 11 0
CSS syntax 12 0
HTML syntax 11 0
XML syntax 11 0
JavaScript minifier 12 0
CSS minifier 14 0
HTML minifier 19 0
XML minifier 14 0
JSON minifier 1 0
development build 438 103
production build 445 133
watch with HMR, one rebuild 449 110

From Module loading run #222.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Async tap wrappers now replace the callback in the original argument array. HMR, loader, resolve, and utility code also receive more specific JSDoc types and cache annotations. The described type changes do not alter runtime behavior.

Changes: Async tap callbacks

Layer / File(s) Summary
Async tap callback wrappers
lib/debug/ProfilingPlugin.js, lib/performance/HotspotsPlugin.js
Both wrappers replace the final callback argument before invoking the tap. The profiling wrapper ends the trace event before forwarding callback results; the hotspots wrapper measures the callback.

Type refinements

Layer / File(s) Summary
WebpackRequire annotations
lib/hmr/HotModuleReplacement.runtime.js, lib/hmr/JavascriptHotModuleReplacement.runtime.js
HMR annotations use WebpackRequire for the require function, its return value, forwarded properties, and the injected global.
WeakKey and cache types
lib/resolve/getResolveOptionsKey.js, lib/util/WeakTupleMap.js, lib/util/identifier.js, lib/util/cleverMerge.js
Weak-map-related annotations use WeakKey instead of EXPECTED_OBJECT. cleverMerge.js adds cache typedefs and adjusts where it applies casts.
Loader and schema annotations
lib/loaders/LoaderOptionsPlugin.js, lib/util/validateSchema.js
LoaderOptionsPlugin removes the LoaderContext typedef and narrows the context annotation. PrecompiledCheck no longer defaults its type parameter to unknown.

Possibly related issues

  • webpack/webpack issue 23030: This PR adds typed cache views and replaces cache type escape hatches in cleverMerge.js, matching the issue’s request to remove type escapes there.

Suggested labels: area: watch, area: loaders, area: types

Change: Refactor

Merge Risk: Minimal · up to 7bf5a

No actionable merge-blocking risk is identified in the reviewed changes.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Inconclusive The title uses the allowed Conventional Commit type refactor, omits the optional scope correctly, and describes the type-safety changes. The branch prefix is not provided, so the required type-prefi… Provide the branch name or branch prefix to verify that refactor matches it.
Passed Passed checks: 3 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title uses the allowed Conventional Commit type refactor, omits the optional scope correctly, and describes the type-safety changes. The branch prefix is not provided, so the required type-prefix match cannot be verified.

Resolution

Provide the branch name or branch prefix to verify that refactor matches it.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share
  • X
  • Mastodon
  • Reddit
  • LinkedIn
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: webpack/webpack
  • Branch: refactor/close-written-escapes
  • File: .coderabbit.yaml
  • Commit: 7bf5a54
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: baff53e5-bf4e-4df1-8e35-b3767a4278e4
Commits

Reviewing files that changed from the base of the PR and between 58bbf0f and 7bf5a54.

Files ignored due to path filters: 1
  • types.d.ts is excluded by !types.d.ts
Files selected for processing: 10
  • lib/debug/ProfilingPlugin.js
  • lib/hmr/HotModuleReplacement.runtime.js
  • lib/hmr/JavascriptHotModuleReplacement.runtime.js
  • lib/loaders/LoaderOptionsPlugin.js
  • lib/performance/HotspotsPlugin.js
  • lib/resolve/getResolveOptionsKey.js
  • lib/util/WeakTupleMap.js
  • lib/util/cleverMerge.js
  • lib/util/identifier.js
  • lib/util/validateSchema.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@codspeed

codspeed Bot commented Nov 4, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×2.5

1 warning, 1 note

⚠️ 117 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 39 benchmarks have no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 1 improved benchmark
✅ 350 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Memory benchmark "three-long", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 360.1 KB 142.4 KB ×2.5

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing refactor/close-written-escapes (7bf5a54) with main (58bbf0f)

Open in CodSpeed
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexander-akait
alexander-akait merged commit 1211d0f into main Nov 4, 2026
55 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@alexander-akait
alexander-akait deleted the refactor/close-written-escapes branch November 4, 2026 15:32
This was referenced Nov 4, 2026
fix: hold function cache keys weakly and create workers from imported calls #23127
Merged
refactor: type module graph meta keys as WeakKey #23136
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

area: loaders Loader execution and loader API (lib/loaders) area: types types.d.ts, JSDoc annotations, hand-maintained declarations area: watch Watching, HMR, lazy compilation (lib/hmr, hot/)

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@alexander-akait
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.