Repository navigation
Commit 21af4f5
authored
fix(css): terminate a string or url() the tokenizer closed at EOF (#21624)
* test(css): read the equivalence probe's style with no transition in flight
A declaration carrying `transition-*` started a CSS transition on the
shared probe, so `getComputedStyle` returned a value interpolating away
from the previous rule's rather than the one the declaration sets. The
walk order is deterministic, so the two arms read different points of the
same animation and one fixture was filed as a printer defect it never had.
* fix(css): terminate a string or url() the tokenizer closed at EOF
CSS Syntax 4.3.5 and 4.3.6 end a string and a url-token at EOF, so their
content stops there. The printer re-emitted the token as written and then
wrote the enclosing `}`, which the still-open token took into its content:
`.a{content:"abc` printed as `.a{content:"abc}`. Write the terminator back
so the token ends where it ended for the tokenizer. A terminator that is
itself escaped (`"x\\"`) does not close the token, so the check counts
trailing backslashes rather than reading the last character.
* fix: register ModuleDependencyError as serializable
A module that records one could not be written to the persistent cache —
"No serializer registered for ModuleDependencyError" — so the pack was
invalidated and the module rebuilt on every run. Its structurally
identical sibling ModuleDependencyWarning was already registered.
* fix: guard ModuleDependencyError against deserialization with no error
Deserialization constructs the class with no arguments, so `err.message`
threw and every restore of a cached compilation error failed. With the
guard the `html/srcset` case restores from the persistent cache and its
`test.filter.js` skip can go.
* test(html): run the three error cases under the persistent cache suite
webpack always rebuilds a module that carries a build error, so the pack
is written to on every run. That is expected, and the repo already states
it with an `infrastructure-log.js` expectation; these three cases skipped
the whole cache suite instead.
* fix(css): keep the url() replacement character when closing at EOF
A dangling `\` is dropped when a string is closed at EOF (4.3.5 has it
contribute nothing) but not when a url is: 4.3.6 reads it as an escape and
4.3.7 ends one at EOF with U+FFFD, so dropping it changed the url's value.
Write that code point back instead.
* feat(css): resolve `true` / `false` and nested `@custom-media` values
Media Queries 5 3 defines `true` and `false` as always- and never-matching,
and lets a value name another custom media. Both were classified unsupported
and left as written.
No `<media-in-parens>` is unconditionally true on every engine, so a constant
is folded into the query around it instead of written out: it drops out of an
`and` / `or` chain, takes the whole query with it when it decides one, and a
list with nothing left prints `not all`. A name standing for another resolves
transitively, with a cycle falling back to the old leave-as-written warning.
Definitions now hold their classification rather than their tokens — node ids
are recycled per top-level rule, so an at-rule's AST cannot outlive the walk
that reaches it, and a name may be defined below its use.
* feat(html): reconcile the <head> on hot update instead of reloading
Any `<head>` edit beyond `<title>` reloaded the page, because replacing
`document.head.innerHTML` would tear down the runtime scripts and stylesheet
links webpack injects there on load. Applying only the delta between the two
authored heads cannot: neither string contains an injected node.
A `<script>` in the delta still reloads — one parsed out of a string carries
the already-started flag, so inserting it would never run it — as does a
removal whose element is no longer in the head.
FakeDocument now parses an `innerHTML` fragment (through webpack's own HTML
parser) and exposes `children` / `outerHTML`, which the reconciliation walks.
* docs: treat a persistent-cache invalidation as a defect, not noise
`Pack got invalid because of write to: X` names something that was rebuilt
rather than restored — work a user's incremental build redoes every time. The
guide had no rule for it, so the reflex was to drop the case from the cache
suite with a `test.filter.js`, which removes every cache assertion the case
had. Name the diagnostics that point at the real cause, allow exactly the one
expected write webpack ships (a module carrying a build error is rebuilt
unconditionally), and require any other expectation to carry its reason.
`define-plugin-runtime-value-errors` was skipping the cache suite for that
one expected write; it states it and runs cached now. The other two opt-outs
assert a throw from `webpack()` itself, which the pre-compile runs have
nowhere to report — they keep the filter, with the reason written down.
* perf(css): stop allocating while capturing a media prelude
Capturing walked node arrays, so every level sliced a fresh one and every
`@media` in a file that defines a custom media built a tree even with no
reference in it. Walk index ranges instead, and check for a reference first —
`childAt` reaches the nested blocks without materializing a child list.
On a stylesheet with one `@custom-media` and 200 unrelated `@media` rules the
capture allocates 1 node instead of 801 and 0 arrays instead of 1604. Emitted
bytes and warnings are unchanged on that file and on both custom-media cases.
* feat(html): run a <script> added to the <head> instead of reloading
An element parsed out of a string carries the already-started flag, so
appending it never runs it — the reconciliation reloaded on any <script> in
the delta. Building a fresh element from its attributes and body does run it,
which is what the reload it replaces would have done.
Removing one still reloads: a script that has run cannot be un-run.
FakeDocument grew what that walks — attributes off the parsed fragment, an
outerHTML serialized from the element's own state rather than the source that
spelled it, and a load that fires only for a script that has a src, matching
when a browser fetches one.
* fix: compare memory-cache etags by value, not by object identity
A miss in the memory cache returns `null`, and `null` bails `Cache.hooks.get`
— so it is not "ask the next stage", it is "definitively not cached", and the
file cache is never consulted. Etags were compared by identity, so any asset
whose `Source` is rebuilt each compilation missed on an etag that stringifies
identically to the stored one, then recomputed and stored: re-minified every
build, and the pack invalidated with it.
Three cases already recorded the symptom as unavoidable — "each time returns
different OriginalSource … this prevents hit in inmemory cache". Identity
still decides a hit first, so a warm hit costs no hashing; only a mismatch
falls back to the value the rest of the cache compares etags by.
Ten `infrastructure-log.js` expectations go with it, and stand as the
regression test: they fail again the moment the pack is written to.
* fix: fall through on a memory-cache etag mismatch instead of reporting a miss
Comparing the stringified etags was treating the symptom. A lazy etag is
interned per source object (`getLazyHashedEtag` keys a WeakMap by it), so
equal content reached through a second object is a different etag by
construction — and hashing to tell those apart would cost every hit exactly
what laziness saves.
The defect is that the memory layer answered `null` there. `hooks.get` is an
`AsyncSeriesBailHook`, so `null` bails the chain and the file cache — which
compares etags by value — is never asked. It also buys the caller nothing:
`Cache.get` maps `null` to `undefined` either way. So a mismatch now falls
through, and only an identifier nothing was known about records a miss: an
entry reached with a different etag still answers its own.
Measured on a two-run build of `benchmarkCases/cache-filesystem`: 1029
identity hits out of 2556 gets and zero fall-throughs, so the added stage
costs nothing outside the pattern it fixes.
* fix: keep a nested custom-media reference, and place a head addition in order
Two review findings, both real.
`classifyCustomMedia` read a leading `(--name)` as the whole value, so
`@custom-media --a (--b) and (min-width: 1px)` resolved to `--b` and dropped
the rest. Only a block that *is* the whole value is an alias now; a reference
anywhere else makes the value unresolvable, because nothing outside a `@media`
prelude scans for one — the same hole was open in `not (--b)` and in a comma
segment, and both are closed too.
The head reconciliation appended every addition, so an element authored
between two others landed after them and changed the cascade. Retained
elements are now paired with their live nodes scanning only forward, which
places each addition before the element it precedes and turns a reordering the
delta cannot express into the reload it needs.
FakeDocument's `insertBefore` ignored its reference argument, and parsing into
a detached container registered its children document-wide.1 parent 57177cc commit 21af4f5
57 files changed
Lines changed: 1437 additions & 341 deletions
File tree
- .changeset
- lib
- cache
- css
- errors
- html
- util
- test
- configCases
- assets/delete-asset
- css
- custom-media-selectors
- custom-media-warnings
- minimize-experiments-auto
- minimize-experiments-true
- minimize-user-minimizer
- ecmaVersion/browserslist-missing
- html
- generate-error
- minimize-experiments-auto
- minimize-experiments-true
- minimize-user-minimizer
- script-null-char
- srcset
- template-non-string
- module/check-defaults
- plugins
- define-plugin-runtime-value-errors
- manifest-plugin
- process-assets/html-plugin
- source-map/extract-source-map
- helpers
- hotCases/html
- html-head-change
- html-head-order
- html-head-script-change
- html-head-script-removed
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
503 | 503 | | |
504 | 504 | | |
505 | 505 | | |
506 | | - | |
| 506 | + | |
507 | 507 | | |
508 | | - | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
509 | 530 | | |
510 | 531 | | |
511 | 532 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
37 | 44 | | |
38 | 45 | | |
39 | | - | |
40 | | - | |
41 | | - | |
| 46 | + | |
42 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
43 | 52 | | |
44 | 53 | | |
45 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
119 | 134 | | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | 135 | | |
125 | 136 | | |
126 | | - | |
127 | | - | |
128 | | - | |
| 137 | + | |
129 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
130 | 143 | | |
131 | 144 | | |
132 | 145 | | |
| |||
0 commit comments