Skip to content

Commit 00fcc6a

Browse files
authored
Prevent duplicate workshop-page view transitions during hash navigation (#2386)
1 parent 2f5fae7 commit 00fcc6a

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

scripts/build-docs.test.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,19 @@ test("workshop Markdown uses GitHub emoji shortcodes", () => {
191191
}
192192
});
193193

194-
test("hash navigation opens details ancestors for targeted anchors", () => {
194+
test("hash navigation opens details ancestors after the destination page switches", () => {
195195
const { html } = buildDocs();
196196

197197
assert.match(
198198
html,
199199
/function openDetailsAncestors\(target\) \{[\s\S]*detail\.open = true;[\s\S]*\}/
200200
);
201-
assert.equal((html.match(/openDetailsAncestors\(target\);/g) ?? []).length, 2);
201+
assert.match(
202+
html,
203+
/showWorkshopPage\(target, scrollPage && isPageTarget\);\s*if \(!isPageTarget\) \{\s*openDetailsAncestors\(target\);/
204+
);
205+
assert.match(
206+
html,
207+
/showWorkshopPage\(target, isPage\);\s*if \(!isPage\) \{\s*openDetailsAncestors\(target\);/
208+
);
202209
});

scripts/lib/page-template.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,11 @@ ${htmlContent}</main>
227227
return;
228228
}
229229
230-
openDetailsAncestors(target);
231230
const isPageTarget = target.matches('.markdown-body > details');
232231
showWorkshopPage(target, scrollPage && isPageTarget);
232+
if (!isPageTarget) {
233+
openDetailsAncestors(target);
234+
}
233235
if (scrollPage && !isPageTarget) {
234236
target.scrollIntoView({ block: 'start' });
235237
}
@@ -274,9 +276,11 @@ ${htmlContent}</main>
274276
if (menuDialog.open) menuDialog.close();
275277
const isPage = target.matches('.markdown-body > details');
276278
history.pushState(null, '', link.getAttribute('href'));
277-
openDetailsAncestors(target);
278279
showWorkshopPage(target, isPage);
279-
if (!isPage) target.scrollIntoView({ block: 'start' });
280+
if (!isPage) {
281+
openDetailsAncestors(target);
282+
target.scrollIntoView({ block: 'start' });
283+
}
280284
}
281285
});
282286

0 commit comments

Comments
 (0)