Backtestshugorun-20261024-162305#15207

Issue #15207 Merged fix PR #15210 Run 24 Oct 2026 · run-20261024-162305 gohugoio/hugo

panic: slice bounds out of range in contentNodeShifter.Delete when removing draft pages from a multilingual taxonomy

Better

Our patch was judged better than the merged fix.

In this judgment, Patch B = our agent, Patch A = the merged fix.

Both patches make the same core fix: the contentNodes branch of Delete/DeleteFunc previously mutated the slice in place while ranging over it (append(v[:i], v[i+1:]...)), so a second match at a stale index caused the out-of-bounds panic, and the shrunken slice header was never written back to the tree. Both rewrite this to build a fresh remaining slice, extend the Shifter interface to return the updated value, and have NodeShiftTree.delete/DeleteFuncRaw re-insert the updated node when something was deleted but the entry is not empty. The independent tests confirm both resolve the panic identically. The differences are in tests and craft. Patch A's test only exercises the shifter in isolation, so it would not catch a missing write-back in nodeshifttree.go, which is half of the fix. Patch B's tests drive the real NodeShiftTree via Shape(vec).Delete and DeleteFuncRaw, assert via GetRaw that the remaining nodes are actually persisted, that the key is removed once empty, and add a case for a contentNodesMap nested inside contentNodes losing only one dimension, plus an adjacent-match DeleteFunc case. Patch B also preallocates the remaining slice and documents why a new slice is required (shared backing array with the header stored in the tree), making the intent clearer to future readers. Patch A's nil-initialized remaining is functionally fine but offers no explanation. Scope is identical. B is the better patch on test strength and clarity.

Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.

Solve

57m 4s

Wall-clock time in the container

Full test suite

No new failures

2,245 passed · 6 skipped · 2,301 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

231vs 161 merged

Changed lines, ours vs merged

What version of Hugo are you using?

Reproduced on both:

hugo v0.159.1-86c7d3afacab79dc53325602d77ef884b7570268+extended darwin/arm64
hugo v0.164.0+extended+withdeploy darwin/arm64

Does this issue reproduce with the latest release?

Yes (0.164.0).

What did you expect to see?

A production build (no -D) of a multilingual site containing draft pages completes.

What did you see instead?

panic: runtime error: slice bounds out of range [5:4]

goroutine 37 [running]:
github.com/gohugoio/hugo/hugolib.(*contentNodeShifter).Delete(0x..., {0x..., 0x...}, {0x2, 0x0, 0x0})
	github.com/gohugoio/hugo/hugolib/content_map_page_contentnodeshifter.go:48 +0x5f4
github.com/gohugoio/hugo/hugolib/doctree.(*NodeShiftTree[...]).delete(0x..., {0x..., 0x35})
	github.com/gohugoio/hugo/hugolib/doctree/nodeshifttree.go:165 +0x84
github.com/gohugoio/hugo/hugolib/doctree.(*NodeShiftTree[...]).Delete(...)
	github.com/gohugoio/hugo/hugolib/doctree/nodeshifttree.go:107
github.com/gohugoio/hugo/hugolib.(*allPagesAssembler).createAllPages.func1-range1(...)
	github.com/gohugoio/hugo/hugolib/content_map_page_assembler.go:106 +0xa4
github.com/gohugoio/hugo/hugolib.(*allPagesAssembler).createAllPages(...)
	github.com/gohugoio/hugo/hugolib/content_map_page_assembler.go:138 +0x168
github.com/gohugoio/hugo/hugolib.(*HugoSites).assemble(...)
	github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:345 +0x41c

The 0x35 in delete(..., {…, 0x35}) is 53, exactly the byte length of the key being removed (/blog/ plus a 47-character slug).

Only on the page-removal path

hugo -D (drafts included) builds fine. The panic appears only when a page is removed from the tree, which makes it invisible in local preview and fatal only in production.

A future publishDate panics identically. Setting [_build] render = "never" / list = "never" on the same pages avoids it entirely — consistent with those pages never being added to the tree, so nothing is deleted.

What I ruled out

Site: 8 languages, ~1,490 pages per language, ~11,455 content files, categories taxonomy.

  • Not a regression. 0.159.1 and 0.164.0 behave identically.
  • Not the number of drafts. 96 draft pages build fine; 16 panic.
  • Not slug length. The panicking key was 47 chars, but renaming an unrelated post to exactly 47 chars builds fine.
  • Not the slug. Renaming the offending page does not help.
  • Not byte layout. Deleting a front-matter line, or adding a blank one, still panics.

Swapping page content at a fixed path isolates it to front matter. Changing categories = ["Airport Operations"] on the offending page to any other value clears the panic — and so does moving a different page out of that same category while leaving the offending one alone. So the trigger is combinatorial: some particular set of pages being deleted from one taxonomy term corrupts the shifter, rather than any single page being malformed.

Reproducer

I have not managed to minimise it, and I want to be upfront about that. Synthetic multilingual sites (8 languages, 12 blog + 200 glossary pages sharing one taxonomy term, varying draft counts) do not reproduce, so something else in the real tree is required. The affected repository is private.

I am happy to run patches or instrumented builds against the real site and report back, which may be faster than guessing at a minimal case.

The two patches

Our patch+202 −29
hugolib/content_map_page_contentnodeshifter.goindex 04f632f75..9d420e9f8 100644@@ -25,7 +25,7 @@ type contentNodeShifter struct { 	conf config.AllProvider // Used for logging/debugging. } -func (s *contentNodeShifter) Delete(n contentNode, vec sitesmatrix.Vector) (contentNode, bool, bool) {+func (s *contentNodeShifter) Delete(n contentNode, vec sitesmatrix.Vector) (contentNode, contentNode, bool, bool) { 	switch v := n.(type) { 	case contentNodesMap: 		deleted, wasDeleted := v[vec]@@ -33,49 +33,61 @@ func (s *contentNodeShifter) Delete(n contentNode, vec sitesmatrix.Vector) (cont 			delete(v, vec) 			resource.MarkStale(deleted) 		}-		return deleted, wasDeleted, len(v) == 0+		return v, deleted, wasDeleted, len(v) == 0 	case contentNodeForSite: 		if v.siteVector() != vec {-			return nil, false, false+			return v, nil, false, false 		} 		resource.MarkStale(v)-		return v, true, true+		return nil, v, true, true 	case contentNodes:-		var deleted contentNodes-		for i, nn := range v {-			if vv, ok, _ := s.Delete(nn, vec); ok {+		// Build a new slice; the backing array of v may be shared with+		// other slice headers (e.g. the one stored in the tree).+		var (+			deleted   contentNodes+			remaining = make(contentNodes, 0, len(v))+		)+		for _, nn := range v {+			updated, vv, ok, isEmpty := s.Delete(nn, vec)+			if ok { 				deleted = append(deleted, vv)-				v = append(v[:i], v[i+1:]...)+			}+			if !isEmpty {+				remaining = append(remaining, updated) 			} 		} 		if len(deleted) == 0 {-			return nil, false, false+			return v, nil, false, false 		}-		return deleted, true, len(v) == 0+		return remaining, deleted, true, len(remaining) == 0 	default: 		v = v.(contentNodeSingle) // Ensure single node. 		resource.MarkStale(v)-		return v, true, true+		return nil, v, true, true  	} } -func (s *contentNodeShifter) DeleteFunc(v contentNode, f func(n contentNode) bool) bool {+func (s *contentNodeShifter) DeleteFunc(v contentNode, f func(n contentNode) bool) (contentNode, bool) { 	switch ss := v.(type) { 	case contentNodeSingle: 		if f(ss) { 			resource.MarkStale(ss)-			return true+			return nil, true 		}-		return false+		return ss, false 	case contentNodes:-		for i, n := range ss {+		// Build a new slice; the backing array of ss may be shared with+		// other slice headers (e.g. the one stored in the tree).+		remaining := make(contentNodes, 0, len(ss))+		for _, n := range ss { 			if f(n) { 				resource.MarkStale(n)-				ss = append(ss[:i], ss[i+1:]...)+				continue 			}+			remaining = append(remaining, n) 		}-		return len(ss) == 0+		return remaining, len(remaining) == 0 	case contentNodesMap: 		for k, n := range ss { 			if f(n) {@@ -83,7 +95,7 @@ func (s *contentNodeShifter) DeleteFunc(v contentNode, f func(n contentNode) boo 				delete(ss, k) 			} 		}-		return len(ss) == 0+		return ss, len(ss) == 0 	default: 		panic(fmt.Sprintf("DeleteFunc: unknown type %T", v)) 	}hugolib/content_map_page_contentnodeshifter_test.gonew file mode 100644index 000000000..b0643718d@@ -0,0 +1,149 @@+// Copyright 2025 The Hugo Authors. All rights reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++package hugolib++import (+	"testing"++	qt "github.com/frankban/quicktest"+	"github.com/gohugoio/hugo/hugolib/doctree"+	"github.com/gohugoio/hugo/hugolib/sitesmatrix"+)++type testContentNodeForSite struct {+	name string+	vec  sitesmatrix.Vector+}++func (n *testContentNodeForSite) Path() string { return "/blog/p1" }++func (n *testContentNodeForSite) siteVector() sitesmatrix.Vector { return n.vec }++func (n *testContentNodeForSite) forEeachContentNode(f func(sitesmatrix.Vector, contentNode) bool) bool {+	return f(n.vec, n)+}++func newTestContentNodeTree() *doctree.NodeShiftTree[contentNode] {+	return doctree.New(doctree.Config[contentNode]{+		Shifter: &contentNodeShifter{},+	})+}++func testContentNodeNames(c *qt.C, n contentNode) []string {+	c.Helper()+	nodes, ok := n.(contentNodes)+	c.Assert(ok, qt.IsTrue, qt.Commentf("expected contentNodes, got %T", n))+	var names []string+	for _, nn := range nodes {+		names = append(names, nn.(*testContentNodeForSite).name)+	}+	return names+}++// Deleting more than one entry from a contentNodes slice in one Delete call+// used to panic with "slice bounds out of range [5:4]".+func TestContentNodeShifterDeleteMultipleFromContentNodes(t *testing.T) {+	c := qt.New(t)++	en := sitesmatrix.Vector{0, 0, 0}+	de := sitesmatrix.Vector{1, 0, 0}++	tree := newTestContentNodeTree()+	const key = "/blog/p1"+	tree.InsertRaw(key, contentNodes{+		&testContentNodeForSite{name: "a", vec: en},+		&testContentNodeForSite{name: "x1", vec: de},+		&testContentNodeForSite{name: "b", vec: en},+		&testContentNodeForSite{name: "c", vec: en},+		&testContentNodeForSite{name: "x2", vec: de},+	})++	deleted, ok := tree.Shape(de).Delete(key)+	c.Assert(ok, qt.IsTrue)+	c.Assert(testContentNodeNames(c, deleted), qt.DeepEquals, []string{"x1", "x2"})++	// The remaining nodes must be written back to the tree.+	n, found := tree.GetRaw(key)+	c.Assert(found, qt.IsTrue)+	c.Assert(testContentNodeNames(c, n), qt.DeepEquals, []string{"a", "b", "c"})++	// Deleting the rest removes the key.+	_, ok = tree.Shape(en).Delete(key)+	c.Assert(ok, qt.IsTrue)+	_, found = tree.GetRaw(key)+	c.Assert(found, qt.IsFalse)+}++// A nested contentNodesMap must only lose the deleted dimension, not all of its entries.+func TestContentNodeShifterDeleteNestedMapInContentNodes(t *testing.T) {+	c := qt.New(t)++	en := sitesmatrix.Vector{0, 0, 0}+	de := sitesmatrix.Vector{1, 0, 0}+	fr := sitesmatrix.Vector{2, 0, 0}++	tree := newTestContentNodeTree()+	const key = "/blog/p1"+	tree.InsertRaw(key, contentNodes{+		contentNodesMap{+			en: &testContentNodeForSite{name: "en", vec: en},+			de: &testContentNodeForSite{name: "de", vec: de},+		},+		&testContentNodeForSite{name: "fr", vec: fr},+	})++	_, ok := tree.Shape(en).Delete(key)+	c.Assert(ok, qt.IsTrue)++	n, found := tree.GetRaw(key)+	c.Assert(found, qt.IsTrue)+	nodes := n.(contentNodes)+	c.Assert(nodes, qt.HasLen, 2)+	m, isMap := nodes[0].(contentNodesMap)+	c.Assert(isMap, qt.IsTrue)+	c.Assert(m, qt.HasLen, 1)+	c.Assert(m[de].(*testContentNodeForSite).name, qt.Equals, "de")+	c.Assert(nodes[1].(*testContentNodeForSite).name, qt.Equals, "fr")+}++// Adjacent matches used to be skipped and the tree kept a stale slice header.+func TestContentNodeShifterDeleteFuncContentNodes(t *testing.T) {+	c := qt.New(t)++	en := sitesmatrix.Vector{0, 0, 0}++	tree := newTestContentNodeTree()+	const key = "/blog/p1"+	tree.InsertRaw(key, contentNodes{+		&testContentNodeForSite{name: "a", vec: en},+		&testContentNodeForSite{name: "x1", vec: en},+		&testContentNodeForSite{name: "x2", vec: en},+		&testContentNodeForSite{name: "b", vec: en},+	})++	_, count := tree.DeleteFuncRaw(key, func(n contentNode) bool {+		name := n.(*testContentNodeForSite).name+		return name == "x1" || name == "x2"+	})+	c.Assert(count, qt.Equals, 2)++	n, found := tree.GetRaw(key)+	c.Assert(found, qt.IsTrue)+	c.Assert(testContentNodeNames(c, n), qt.DeepEquals, []string{"a", "b"})++	_, count = tree.DeleteFuncRaw(key, func(n contentNode) bool { return true })+	c.Assert(count, qt.Equals, 2)+	_, found = tree.GetRaw(key)+	c.Assert(found, qt.IsFalse)+}hugolib/doctree/nodeshiftree_test.goindex 1d17a4129..a969b43fc 100644@@ -258,12 +258,15 @@ func (s *testShifter) Insert(old, new *testValue) (*testValue, *testValue, bool) 	return new, old, true } -func (s *testShifter) Delete(n *testValue, dimension sitesmatrix.Vector) (*testValue, bool, bool) {-	return nil, true, true+func (s *testShifter) Delete(n *testValue, dimension sitesmatrix.Vector) (*testValue, *testValue, bool, bool) {+	return nil, n, true, true } -func (s *testShifter) DeleteFunc(v *testValue, f func(*testValue) bool) bool {-	return f(v)+func (s *testShifter) DeleteFunc(v *testValue, f func(*testValue) bool) (*testValue, bool) {+	if f(v) {+		return nil, true+	}+	return v, false }  func (s *testShifter) Shift(n *testValue, dimension sitesmatrix.Vector, fallback bool) (v *testValue, ok bool) {hugolib/doctree/nodeshifttree.goindex 0ccf3eba3..648518689 100644@@ -49,12 +49,14 @@ type ( 		// and a bool indicating if an existing record is updated. 		Insert(old, new T) (T, T, bool) -		// Delete deletes T from the given dimension and returns the deleted T and whether the dimension was deleted and if  it's empty after the delete.-		Delete(v T, dimension sitesmatrix.Vector) (T, bool, bool)+		// Delete deletes T from the given dimension and returns the updated T (what remains of v,+		// to be stored back in the tree), the deleted T, whether the dimension was deleted and if it's empty after the delete.+		Delete(v T, dimension sitesmatrix.Vector) (T, T, bool, bool)  		// DeleteFunc deletes nodes in v from the tree where the given function returns true.-		// It returns true if it's empty after the delete.-		DeleteFunc(v T, f func(n T) bool) bool+		// It returns the updated T (what remains of v, to be stored back in the tree)+		// and true if it's empty after the delete.+		DeleteFunc(v T, f func(n T) bool) (T, bool)  		// Shift shifts v into the given dimension, 		// if fallback is true, it will fall back a fallback match if found.@@ -118,7 +120,7 @@ func (r *NodeShiftTree[T]) DeleteFuncRaw(key string, f func(T) bool) (T, int) { 		return lastDeleted, count 	} -	isEmpty := r.shifter.DeleteFunc(v, func(n T) bool {+	updated, isEmpty := r.shifter.DeleteFunc(v, func(n T) bool { 		if f(n) { 			count++ 			lastDeleted = n@@ -129,6 +131,8 @@ func (r *NodeShiftTree[T]) DeleteFuncRaw(key string, f func(T) bool) (T, int) {  	if isEmpty { 		r.tree.Delete(key)+	} else if count > 0 {+		r.tree.Insert(key, updated) 	}  	return lastDeleted, count@@ -161,10 +165,15 @@ func (r *NodeShiftTree[T]) delete(key string) (T, bool) { 	var wasDeleted bool 	var deleted T 	if v, ok := r.tree.Get(key); ok {-		var isEmpty bool-		deleted, wasDeleted, isEmpty = r.shifter.Delete(v, r.siteVector)+		var (+			updated T+			isEmpty bool+		)+		updated, deleted, wasDeleted, isEmpty = r.shifter.Delete(v, r.siteVector) 		if isEmpty { 			r.tree.Delete(key)+		} else if wasDeleted {+			r.tree.Insert(key, updated) 		} 	} 	return deleted, wasDeleted 
Merged fix · PR #15210+128 −33
hugolib/content_map_page_contentnodeshifter.goindex 04f632f75..2d8bfa105 100644@@ -25,7 +25,7 @@ type contentNodeShifter struct { 	conf config.AllProvider // Used for logging/debugging. } -func (s *contentNodeShifter) Delete(n contentNode, vec sitesmatrix.Vector) (contentNode, bool, bool) {+func (s *contentNodeShifter) Delete(n contentNode, vec sitesmatrix.Vector) (contentNode, contentNode, bool, bool) { 	switch v := n.(type) { 	case contentNodesMap: 		deleted, wasDeleted := v[vec]@@ -33,49 +33,53 @@ func (s *contentNodeShifter) Delete(n contentNode, vec sitesmatrix.Vector) (cont 			delete(v, vec) 			resource.MarkStale(deleted) 		}-		return deleted, wasDeleted, len(v) == 0+		return v, deleted, wasDeleted, len(v) == 0 	case contentNodeForSite: 		if v.siteVector() != vec {-			return nil, false, false+			return v, nil, false, false 		} 		resource.MarkStale(v)-		return v, true, true+		return nil, v, true, true 	case contentNodes:-		var deleted contentNodes-		for i, nn := range v {-			if vv, ok, _ := s.Delete(nn, vec); ok {+		var deleted, remaining contentNodes+		for _, nn := range v {+			updated, vv, ok, isEmpty := s.Delete(nn, vec)+			if ok { 				deleted = append(deleted, vv)-				v = append(v[:i], v[i+1:]...)+			}+			if !isEmpty {+				remaining = append(remaining, updated) 			} 		} 		if len(deleted) == 0 {-			return nil, false, false+			return v, nil, false, false 		}-		return deleted, true, len(v) == 0+		return remaining, deleted, true, len(remaining) == 0 	default:-		v = v.(contentNodeSingle) // Ensure single node.-		resource.MarkStale(v)-		return v, true, true-+		vv := v.(contentNodeSingle) // Ensure single node.+		resource.MarkStale(vv)+		return nil, vv, true, true 	} } -func (s *contentNodeShifter) DeleteFunc(v contentNode, f func(n contentNode) bool) bool {+func (s *contentNodeShifter) DeleteFunc(v contentNode, f func(n contentNode) bool) (contentNode, bool) { 	switch ss := v.(type) { 	case contentNodeSingle: 		if f(ss) { 			resource.MarkStale(ss)-			return true+			return nil, true 		}-		return false+		return ss, false 	case contentNodes:-		for i, n := range ss {+		var remaining contentNodes+		for _, n := range ss { 			if f(n) { 				resource.MarkStale(n)-				ss = append(ss[:i], ss[i+1:]...)+			} else {+				remaining = append(remaining, n) 			} 		}-		return len(ss) == 0+		return remaining, len(remaining) == 0 	case contentNodesMap: 		for k, n := range ss { 			if f(n) {@@ -83,7 +87,7 @@ func (s *contentNodeShifter) DeleteFunc(v contentNode, f func(n contentNode) boo 				delete(ss, k) 			} 		}-		return len(ss) == 0+		return ss, len(ss) == 0 	default: 		panic(fmt.Sprintf("DeleteFunc: unknown type %T", v)) 	}hugolib/content_map_page_contentnodeshifter_test.gonew file mode 100644index 000000000..f8d2c07bc@@ -0,0 +1,79 @@+// Copyright 2025 The Hugo Authors. All rights reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++package hugolib++import (+	"testing"++	qt "github.com/frankban/quicktest"+	"github.com/gohugoio/hugo/hugolib/sitesmatrix"+)++type testContentNodeForSite struct {+	vec sitesmatrix.Vector+}++func (n *testContentNodeForSite) Path() string                   { return "/test" }+func (n *testContentNodeForSite) nodeCategorySingle()            {}+func (n *testContentNodeForSite) siteVector() sitesmatrix.Vector { return n.vec }+func (n *testContentNodeForSite) forEeachContentNode(f func(sitesmatrix.Vector, contentNode) bool) bool {+	return f(n.vec, n)+}++// See issue 15207.+func TestContentNodeShifterDeleteMultipleFromNodes(t *testing.T) {+	c := qt.New(t)++	s := &contentNodeShifter{}+	vec := sitesmatrix.Vector{2, 0, 0}+	other := sitesmatrix.Vector{1, 0, 0}++	newNodes := func() contentNodes {+		return contentNodes{+			&testContentNodeForSite{vec: other},+			&testContentNodeForSite{vec: vec},+			&testContentNodeForSite{vec: other},+			&testContentNodeForSite{vec: other},+			&testContentNodeForSite{vec: vec},+		}+	}++	updated, deleted, wasDeleted, isEmpty := s.Delete(newNodes(), vec)+	c.Assert(wasDeleted, qt.IsTrue)+	c.Assert(isEmpty, qt.IsFalse)+	c.Assert(deleted.(contentNodes), qt.HasLen, 2)+	remaining := updated.(contentNodes)+	c.Assert(remaining, qt.HasLen, 3)+	for _, n := range remaining {+		c.Assert(n.(contentNodeForSite).siteVector(), qt.Equals, other)+	}++	// Delete all.+	updated, deleted, wasDeleted, isEmpty = s.Delete(contentNodes{+		&testContentNodeForSite{vec: vec},+		&testContentNodeForSite{vec: vec},+	}, vec)+	c.Assert(wasDeleted, qt.IsTrue)+	c.Assert(isEmpty, qt.IsTrue)+	c.Assert(deleted.(contentNodes), qt.HasLen, 2)+	c.Assert(updated, qt.IsNil)++	// Delete none.+	nodes := contentNodes{&testContentNodeForSite{vec: other}}+	updated, deleted, wasDeleted, isEmpty = s.Delete(nodes, vec)+	c.Assert(wasDeleted, qt.IsFalse)+	c.Assert(isEmpty, qt.IsFalse)+	c.Assert(deleted, qt.IsNil)+	c.Assert(updated.(contentNodes), qt.HasLen, 1)+}hugolib/doctree/nodeshiftree_test.goindex 1d17a4129..a969b43fc 100644@@ -258,12 +258,15 @@ func (s *testShifter) Insert(old, new *testValue) (*testValue, *testValue, bool) 	return new, old, true } -func (s *testShifter) Delete(n *testValue, dimension sitesmatrix.Vector) (*testValue, bool, bool) {-	return nil, true, true+func (s *testShifter) Delete(n *testValue, dimension sitesmatrix.Vector) (*testValue, *testValue, bool, bool) {+	return nil, n, true, true } -func (s *testShifter) DeleteFunc(v *testValue, f func(*testValue) bool) bool {-	return f(v)+func (s *testShifter) DeleteFunc(v *testValue, f func(*testValue) bool) (*testValue, bool) {+	if f(v) {+		return nil, true+	}+	return v, false }  func (s *testShifter) Shift(n *testValue, dimension sitesmatrix.Vector, fallback bool) (v *testValue, ok bool) {hugolib/doctree/nodeshifttree.goindex 0ccf3eba3..f2cec9f26 100644@@ -49,12 +49,14 @@ type ( 		// and a bool indicating if an existing record is updated. 		Insert(old, new T) (T, T, bool) -		// Delete deletes T from the given dimension and returns the deleted T and whether the dimension was deleted and if  it's empty after the delete.-		Delete(v T, dimension sitesmatrix.Vector) (T, bool, bool)+		// Delete deletes T from the given dimension.+		// It returns the updated T, the deleted T, whether anything was deleted+		// and whether T is empty after the delete.+		Delete(v T, dimension sitesmatrix.Vector) (T, T, bool, bool) -		// DeleteFunc deletes nodes in v from the tree where the given function returns true.-		// It returns true if it's empty after the delete.-		DeleteFunc(v T, f func(n T) bool) bool+		// DeleteFunc deletes nodes in v where the given function returns true.+		// It returns the updated T and whether it's empty after the delete.+		DeleteFunc(v T, f func(n T) bool) (T, bool)  		// Shift shifts v into the given dimension, 		// if fallback is true, it will fall back a fallback match if found.@@ -118,7 +120,7 @@ func (r *NodeShiftTree[T]) DeleteFuncRaw(key string, f func(T) bool) (T, int) { 		return lastDeleted, count 	} -	isEmpty := r.shifter.DeleteFunc(v, func(n T) bool {+	updated, isEmpty := r.shifter.DeleteFunc(v, func(n T) bool { 		if f(n) { 			count++ 			lastDeleted = n@@ -129,6 +131,8 @@ func (r *NodeShiftTree[T]) DeleteFuncRaw(key string, f func(T) bool) (T, int) {  	if isEmpty { 		r.tree.Delete(key)+	} else if count > 0 {+		r.tree.Insert(key, updated) 	}  	return lastDeleted, count@@ -161,10 +165,15 @@ func (r *NodeShiftTree[T]) delete(key string) (T, bool) { 	var wasDeleted bool 	var deleted T 	if v, ok := r.tree.Get(key); ok {-		var isEmpty bool-		deleted, wasDeleted, isEmpty = r.shifter.Delete(v, r.siteVector)+		var (+			updated T+			isEmpty bool+		)+		updated, deleted, wasDeleted, isEmpty = r.shifter.Delete(v, r.siteVector) 		if isEmpty { 			r.tree.Delete(key)+		} else if wasDeleted {+			r.tree.Insert(key, updated) 		} 	} 	return deleted, wasDeleted