mirror of
https://github.com/discourse/discourse.git
synced 2024-12-19 04:36:27 +08:00
e2f65cd170
Using patch-package is much easier to reason with than maintaining a full fork of virtual-dom. Original reasoning for the fork can be found ine216a98f
Patch is based on the diff atc64007150a (diff-f648eb0588a88af826e29622f64aca611e191c66eb9e79396d559edaef622313)
44 lines
1.5 KiB
Diff
44 lines
1.5 KiB
Diff
diff --git a/node_modules/virtual-dom/vtree/diff.js b/node_modules/virtual-dom/vtree/diff.js
|
|
index b5bccbd..058d6b3 100644
|
|
--- a/node_modules/virtual-dom/vtree/diff.js
|
|
+++ b/node_modules/virtual-dom/vtree/diff.js
|
|
@@ -311,6 +311,38 @@ function reorder(aChildren, bChildren) {
|
|
var inserts = []
|
|
var simulateItem
|
|
|
|
+ // handle prepends without reordering old elements
|
|
+ var shift = bChildren.length - aChildren.length
|
|
+ if (shift > 0 && simulate.length === bChildren.length) {
|
|
+ var prepend = true
|
|
+ for (var i = 0; prepend && i < simulate.length; i++) {
|
|
+ prepend = simulate[i] && simulate[i].key
|
|
+ }
|
|
+ for (var i = 0; prepend && i < aChildren.length; i++) {
|
|
+ prepend = aChildren[i].key === bChildren[i + shift].key
|
|
+ }
|
|
+
|
|
+ if (prepend) {
|
|
+ for (var i = 0; i < shift; i++) {
|
|
+ removes.push({
|
|
+ from: aChildren.length,
|
|
+ key: bChildren[i].key
|
|
+ })
|
|
+ inserts.push({
|
|
+ to: i,
|
|
+ key: bChildren[i].key
|
|
+ })
|
|
+ }
|
|
+ return {
|
|
+ children: newChildren,
|
|
+ moves: {
|
|
+ removes: removes,
|
|
+ inserts: inserts
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
for (var k = 0; k < bChildren.length;) {
|
|
var wantedItem = bChildren[k]
|
|
simulateItem = simulate[simulateIndex]
|