Repository navigation
Commit e3f177c
authored
feat(esm): widen analyzable output to HMR, hashed and function chunk filenames (#21653)
* feat: emit analyzable ESM imports under hot module replacement
The gate refused the analyzable form for any compilation with HMR applied.
The hot require special-cased `ensureChunk` (`.e`) to block an update on a
chunk load in flight and copied everything else through, so `.ei` escaped
that wrapper — and it defined `.e` even when the runtime had none.
Wrap `.ei` the same way and define each wrapper only when it exists. Lazy
compilation generates a proxy between builds rather than from changed source,
so one already loaded outlives the build that required `ensureChunk`; keep it
in the runtime there instead of refusing the analyzable form everywhere.
* feat: bake a url public path into the analyzable wasm binary reference
`supportsAnalyzableWasm` chained through `supportsAnalyzableEsmUrl`, so it
inherited an `auto` public path requirement it does not have: a public path
that is a complete URL bakes just as well, because `new URL(...)` ignores its
base for an absolute specifier.
A root- or directory-relative one still cannot — the runtime form resolves it
against the document and a baked one against the chunk — and neither can a
loader that hands the result to `readFile`, which takes a `file:` URL alone.
Those keep addressing the binary relative to their chunk, as they already did.
* perf: drop the runtime chunk loader from analyzable css and hinted chunks
A chunk carrying css or resource-hint children asked for `ensureChunk` just to
get the `.f` map its handlers attach to, and that pulled in the js chunk loader
and the chunk id to filename table behind it — the runtime the analyzable form
exists to replace. `.ei` dispatches every handler but `.f.j` itself, so ask for
the map alone and let `EnsureChunkRuntimeModule` emit `.e` only where it is used.
The hot runtime registers its own handler on the map and force-loads through the
others by bare chunk id, so HMR keeps both the map and the loader — which an
all-analyzable graph had silently been dropping since HMR started emitting the
analyzable form.
* feat: support a function output.chunkFilename in analyzable ESM output
A function was refused on its type alone, without asking what it returns. Call it
for its template instead, and apply the same hash test to the answer.
No hash is knowable at this point — during code generation `chunk.contentHash` is
still empty and `chunk.hash` unset — so a function reading one would name a file
that is never emitted. A second call against a stand-in chunk carrying sentinel
hashes says whether the answer depends on them; one that does keeps the runtime
form, as does a template with a hash placeholder in it.
* feat: bake a hashed chunk filename into the analyzable specifier
A hashed name is settled long after the code referencing it is generated, so the
specifier is emitted as a stand-in and filled in once the hash exists. That covers
`output.chunkFilename` carrying any hash, and so `[fullhash]` in a WebAssembly
filename too — the last names the analyzable form could not address.
The stand-in carries the prefix and chunk id rather than an index into per-build
state: a module restored from the persistent cache is never generated again, and
one that outlived its registry would reach the bundle unreplaced.
Substituting rewrites a chunk after its own content hash was taken, so the form is
kept only where `optimization.realContentHash` brings the two back in line.
* fix: resolve a deferred chunk specifier with the runtime as well
The stand-in was filled in from a path missing `runtime`, which the call naming
the asset passes. A `[runtime]` in the template then resolved to `_` rather than
the runtime's name, so the specifier addressed a file that is never emitted.
Cover every placeholder a chunk filename can carry, asserting the baked name is
one on disk instead of a string fixed in the test.
* feat: defer a hash-dependent function chunk filename instead of refusing it
The probe telling whether a function's answer depends on a hash meant "fall
back", from when nothing could resolve one later. The deferred pass asks the
function again with the hashes settled, so it now means "defer" — `null` stays
for a function that throws, which no later call rescues.
Both hash-bearing shapes bake as a result: a template carrying a placeholder,
and a name built from `pathData` directly.
* refactor: drop the unreachable chunk id guard from the analyzable import
`blockPromise` drops any chunk without an id before it calls, so the check
never fired — measured across the config and stats suites, where the operand
was evaluated 296 times and was true none of them.
The one in `_getAnalyzableChunkSpecifier` stays: `WorkerDependency` reaches
that without the same filter, and an id-less stand-in would reach the bundle
verbatim instead of falling back. Says so now.
* fix(esm): probe every content-hash type when a chunk filename is a function
A function `output.chunkFilename` reading `contentHash.css` saw the same missing
value in both calls, so the name looked constant and `undefined` was baked into
the specifier. Probe with two distinct hashes exposed for every type instead.
Also skip the analyzable HMR case where ESM output cannot build `require`, and
reject a stand-in payload that is not a chunk reference.
* fix(esm): resolve an analyzable chunk specifier with the runtime as well
`[runtime]` and `pathData.runtime` were absent where the specifier is baked, so
both read back empty and the name looked settled — `src_lazy_js.undefined.mjs`
was emitted against a `src_lazy_js.main.mjs` on disk. Hand the runtime to every
site that resolves a chunk filename, as the deferred pass already does.
* chore: bring the changeset entry under the length limit
* fix(esm): defer a chunk name built by enumerating the content hashes
Which content hashes a chunk carries is settled no earlier than their values
are, so a filename function reading `Object.keys(chunk.contentHash)` saw an
empty set in both probes and baked `src_lazy_js.none.mjs` against a
`src_lazy_js.javascript-css.mjs` on disk. The probes now disagree about which
hashes exist, so asking defers just as reading one does.
* chore: tighten two comments in the wasm analyzable url case
* perf(esm): keep the runtime chunk loader out of HMR builds without async chunks
The hot runtime force-loads through the handler map by bare chunk id, so
the analyzable path keeps `.f.j` around — but only where there is an async
chunk to force-load. Requiring it unconditionally pulled the handler map,
the chunk-filename helper and the whole `import()` loader into every
`output.module` HMR build: +2.80 KiB on configCases/module/import-meta-hot-priority.1 parent 23642ae commit e3f177c
36 files changed
Lines changed: 930 additions & 65 deletions
File tree
- .changeset
- lib
- esm
- hmr
- runtime
- web
- test
- configCases
- analyzable
- css-chunk-import
- css-content-hash-filename
- function-chunk-filename
- hashed-chunk-filename
- wasm/analyzable-url-public-path
- hotCases/esm-output/analyzable-import
- statsCases/analyzable-esm-fallbacks
- __snapshots__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
573 | 574 | | |
574 | 575 | | |
575 | 576 | | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
576 | 594 | | |
577 | 595 | | |
578 | 596 | | |
579 | 597 | | |
580 | 598 | | |
581 | 599 | | |
582 | 600 | | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
| 601 | + | |
588 | 602 | | |
589 | 603 | | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
590 | 610 | | |
591 | 611 | | |
592 | 612 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
62 | 68 | | |
63 | 69 | | |
64 | 70 | | |
65 | 71 | | |
66 | 72 | | |
| 73 | + | |
| 74 | + | |
67 | 75 | | |
68 | 76 | | |
69 | 77 | | |
| |||
76 | 84 | | |
77 | 85 | | |
78 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
79 | 122 | | |
80 | 123 | | |
81 | 124 | | |
| |||
322 | 365 | | |
323 | 366 | | |
324 | 367 | | |
325 | | - | |
| 368 | + | |
| 369 | + | |
326 | 370 | | |
327 | 371 | | |
328 | 372 | | |
| |||
332 | 376 | | |
333 | 377 | | |
334 | 378 | | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
335 | 396 | | |
336 | 397 | | |
337 | 398 | | |
| |||
1669 | 1730 | | |
1670 | 1731 | | |
1671 | 1732 | | |
| 1733 | + | |
1672 | 1734 | | |
1673 | 1735 | | |
1674 | 1736 | | |
1675 | 1737 | | |
1676 | | - | |
1677 | 1738 | | |
1678 | 1739 | | |
1679 | 1740 | | |
1680 | 1741 | | |
1681 | 1742 | | |
1682 | | - | |
1683 | | - | |
1684 | | - | |
1685 | | - | |
1686 | | - | |
1687 | | - | |
1688 | | - | |
1689 | | - | |
1690 | | - | |
1691 | | - | |
| 1743 | + | |
| 1744 | + | |
1692 | 1745 | | |
1693 | 1746 | | |
1694 | 1747 | | |
| |||
1743 | 1796 | | |
1744 | 1797 | | |
1745 | 1798 | | |
1746 | | - | |
1747 | | - | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
1748 | 1802 | | |
1749 | 1803 | | |
1750 | 1804 | | |
| |||
1779 | 1833 | | |
1780 | 1834 | | |
1781 | 1835 | | |
1782 | | - | |
| 1836 | + | |
1783 | 1837 | | |
1784 | 1838 | | |
1785 | 1839 | | |
| |||
1817 | 1871 | | |
1818 | 1872 | | |
1819 | 1873 | | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
1820 | 1882 | | |
1821 | | - | |
1822 | | - | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
1823 | 1888 | | |
1824 | 1889 | | |
1825 | 1890 | | |
1826 | | - | |
1827 | | - | |
1828 | | - | |
1829 | | - | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
1830 | 1913 | | |
1831 | 1914 | | |
1832 | 1915 | | |
1833 | | - | |
| 1916 | + | |
1834 | 1917 | | |
1835 | 1918 | | |
1836 | 1919 | | |
1837 | 1920 | | |
1838 | | - | |
| 1921 | + | |
1839 | 1922 | | |
1840 | 1923 | | |
1841 | 1924 | | |
1842 | | - | |
| 1925 | + | |
1843 | 1926 | | |
1844 | 1927 | | |
1845 | 1928 | | |
1846 | 1929 | | |
1847 | | - | |
| 1930 | + | |
1848 | 1931 | | |
1849 | 1932 | | |
1850 | 1933 | | |
| |||
1864 | 1947 | | |
1865 | 1948 | | |
1866 | 1949 | | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
1867 | 1963 | | |
1868 | 1964 | | |
1869 | 1965 | | |
| |||
1878 | 1974 | | |
1879 | 1975 | | |
1880 | 1976 | | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
1881 | 2034 | | |
1882 | 2035 | | |
1883 | 2036 | | |
| |||
0 commit comments