Skip to content

Commit dd47b7c

Browse files
authored
fix(gatsby-plugin-sitemap): remove splice for default filter (#37916)
1 parent ccb0e7a commit dd47b7c

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

packages/gatsby-plugin-sitemap/src/__tests__/internals.js

+25
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,29 @@ describe(`gatsby-plugin-sitemap internals tests`, () => {
9797

9898
expect(results).toMatchSnapshot()
9999
})
100+
101+
it(`pageFilter should filter correctly on consecutive runs`, () => {
102+
const allPages = [
103+
{ path: `/to/keep/1` },
104+
{ path: `/to/keep/2` },
105+
{ path: `/404.html` },
106+
]
107+
const filterPages = jest.fn()
108+
109+
const { filteredPages } = pageFilter({
110+
allPages,
111+
filterPages,
112+
excludes: [],
113+
})
114+
expect(filteredPages).toHaveLength(2)
115+
expect(filteredPages).not.toContainEqual({ path: `/404.html` })
116+
117+
const { filteredPages: filteredPages2 } = pageFilter({
118+
allPages,
119+
filterPages,
120+
excludes: [],
121+
})
122+
expect(filteredPages2).toHaveLength(2)
123+
expect(filteredPages2).not.toContainEqual({ path: `/404.html` })
124+
})
100125
})

packages/gatsby-plugin-sitemap/src/internals.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,14 @@ export function pageFilter({ allPages, filterPages, excludes }) {
161161

162162
// TODO we should optimize these loops
163163
const filteredPages = allPages.filter(page => {
164-
const defaultFilterMatches = defaultExcludes.some((exclude, i, arr) => {
164+
const defaultFilterMatches = defaultExcludes.some(exclude => {
165165
try {
166166
const doesMatch = defaultFilterPages(page, exclude, {
167167
minimatch,
168168
withoutTrailingSlash,
169169
resolvePagePath,
170170
})
171171

172-
// default excludes can only be found once, so remove them from the arr once excluded
173-
if (doesMatch) {
174-
arr.splice(i, 1)
175-
}
176-
177172
return doesMatch
178173
} catch {
179174
throw new Error(`${REPORTER_PREFIX} Error in default page filter`)

0 commit comments

Comments
 (0)