Skip to content

A platform for community discussion. Free, open, simple.

REVERT: "UX: Aggressive mobile collapse for nested topic view (#40548)" (#40651)

Mark VanLandinghamff45f6e4325d
diff --git a/app/assets/stylesheets/common/nested-view.scss b/app/assets/stylesheets/common/nested-view.scss
index 770e91d8b07..dfb38145d50 100644
--- a/app/assets/stylesheets/common/nested-view.scss
+++ b/app/assets/stylesheets/common/nested-view.scss
@@ -781,26 +781,6 @@
color: var(--primary-low-mid);
}
- &__collapsed-avatar {
- display: flex;
- flex: 0 0 var(--nested-avatar-size);
- align-items: center;
- justify-content: center;
- width: var(--nested-avatar-size);
- height: var(--nested-avatar-size);
- color: var(--primary-low-mid);
-
- .avatar {
- width: var(--nested-avatar-size);
- height: var(--nested-avatar-size);
- }
-
- .d-icon {
- width: 14px;
- height: 14px;
- }
- }
-
&__collapsed-username {
color: var(--primary-high-or-secondary-low);
}
@@ -944,6 +924,50 @@
}
}
+// ── Context view ──────────────────────────────────────────────────
+.nested-context-view {
+ &__banner {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: 0.5em;
+ padding: 0.75em 1em;
+ margin-bottom: 1em;
+ background: var(--tertiary-very-low);
+ border: 1px solid var(--tertiary-low);
+ border-radius: var(--d-border-radius);
+ font-size: var(--font-down-1);
+ position: sticky;
+ top: var(--header-offset, 0);
+ z-index: 9;
+ }
+
+ &__banner-icon {
+ color: var(--tertiary);
+
+ .d-icon {
+ width: 1em;
+ height: 1em;
+ }
+ }
+
+ &__banner-text {
+ color: var(--primary-high);
+ margin-right: auto;
+ }
+
+ &__nav {
+ display: flex;
+ gap: 0.5em;
+ align-items: center;
+ }
+
+ &__chain {
+ border-left: 3px solid var(--tertiary-low);
+ padding-left: 0.75em;
+ }
+}
+
// ── Deep-link highlight animation ──────────────────────────────────
.nested-post--highlighted {
animation: nested-post-highlight 2s ease-out;
@@ -1049,6 +1073,14 @@
flex-wrap: wrap;
}
+ .nested-context-view__banner {
+ margin-left: -0.5em;
+ margin-right: -0.5em;
+ border-radius: 0;
+ border-left: none;
+ border-right: none;
+ }
+
// Full-width cards: break out of container side padding
.nested-view__op,
.nested-view__roots {
@@ -1084,12 +1116,9 @@
}
.nested-view__mobile-focus {
- --nested-mobile-ancestor-avatar-size: 24px;
display: flex;
flex-direction: column;
gap: 0;
- margin-left: -0.5em;
- margin-right: -0.5em;
}
.nested-view__mobile-ancestors {
@@ -1106,7 +1135,7 @@
gap: 0.5em;
width: 100%;
min-width: 0;
- min-height: calc(var(--nested-mobile-ancestor-avatar-size) + 1em);
+ min-height: calc(var(--nested-avatar-size) + 1em);
padding: 0.5em;
color: var(--primary-medium);
background: var(--secondary);
@@ -1135,26 +1164,10 @@
.nested-view__mobile-ancestor {
border-top: 1px solid var(--primary-low);
font-size: var(--font-down-1);
- min-height: calc(var(--nested-mobile-ancestor-avatar-size) + 0.75em);
+ min-height: calc(var(--nested-avatar-size) + 0.75em);
padding-block: 0.375em;
}
- .nested-view__mobile-ancestor-avatar {
- display: flex;
- flex: 0 0 var(--nested-mobile-ancestor-avatar-size);
- align-items: center;
- justify-content: center;
- width: var(--nested-mobile-ancestor-avatar-size);
- height: var(--nested-mobile-ancestor-avatar-size);
-
- .avatar {
- width: var(--nested-mobile-ancestor-avatar-size);
- height: var(--nested-mobile-ancestor-avatar-size);
- max-width: var(--nested-mobile-ancestor-avatar-size);
- max-height: var(--nested-mobile-ancestor-avatar-size);
- }
- }
-
.nested-view__mobile-ancestor-meta {
display: flex;
align-items: baseline;
@@ -1179,6 +1192,8 @@
.nested-view__mobile-focused-branch {
display: flex;
flex-direction: column;
+ margin-left: -0.5em;
+ margin-right: -0.5em;
margin-top: 0.5em;
}
@@ -1224,16 +1239,13 @@
}
// ── Individual nested post overrides ──
- // Gutter becomes a compact rail column. The post article spans the rail and
- // content columns because mobile renders the avatar inline in the header,
- // while children remain indented in the content column.
+ // Gutter shrinks to a narrow line-only column (avatar rendered inline
+ // in the header instead). Lines run full subtree height.
.nested-post {
--nested-line-gutter: 14px;
- --nested-column-gap: var(--space-1);
- --nested-mobile-line-offset: calc(var(--nested-line-gutter) / 2);
- --nested-mobile-line-start: calc(var(--nested-avatar-size) + 6px);
+ --nested-column-gap: var(--space-2);
--nested-mobile-content-indent: calc(
- var(--nested-avatar-size) + var(--space-1)
+ var(--nested-avatar-size) + var(--nested-column-gap)
);
grid-template-columns: var(--nested-line-gutter) 1fr;
@@ -1247,25 +1259,15 @@
--nested-vertical-gap: 0.25em;
// Gutter spans all grid rows so the depth-line runs continuously
- // through the article and children areas.
+ // through the article AND children areas
> .nested-post__gutter {
grid-row: 1 / -1;
- position: relative;
- z-index: 1;
- pointer-events: none;
}
- // Depth-line: vertical bar under the avatar, no decorative hooks.
+ // Depth-line: full-height vertical bar, no decorative hooks
> .nested-post__gutter .nested-post__depth-line {
- position: absolute;
- top: var(--nested-mobile-line-start);
- bottom: 0;
- left: 0;
- min-height: 0;
- pointer-events: auto;
-
&::after {
- left: calc(var(--nested-mobile-line-offset) - 1px);
+ left: calc(var(--nested-line-gutter) / 2 - 1px);
top: 0;
bottom: 0;
}
@@ -1276,7 +1278,7 @@
background: var(--primary-low);
width: 2px;
border-radius: 0;
- left: calc(var(--nested-mobile-line-offset) - 1px);
+ left: calc(var(--nested-line-gutter) / 2 - 1px);
bottom: 0;
}
}
@@ -1288,7 +1290,6 @@
// Inline avatar in the post header (rendered via template)
.nested-post__header .topic-avatar {
- align-self: flex-start;
border-top: none;
float: none;
width: auto;
@@ -1296,30 +1297,14 @@
height: auto;
}
- .nested-post__article,
- .nested-post__collapsed-bar {
- grid-column: 1 / -1;
- }
-
- .nested-post__collapsed-bar {
- padding-inline: 0;
- }
-
- // Mobile strips desktop connector hooks, so the desktop padding used to
- // make room for those hooks must not shift the post's internal grid math.
+ // Strip all decorative connectors (L-hooks, sibling lines)
&:not(.--depth-0) {
- padding-top: 0;
-
&::before,
&:not(:last-child)::after {
content: none;
}
}
- &:not(.--depth-0) + &:not(.--depth-0) {
- margin-top: var(--nested-vertical-gap);
- }
-
// No hover interaction on touch — depth-line handles collapse
> .nested-post__parent-line-btn {
display: none;
@@ -1348,14 +1333,11 @@
.nested-post__content,
.nested-post__menu,
.nested-post__controls,
+ .nested-post__expand-replies,
.post-links-container {
margin-left: var(--nested-mobile-content-indent);
}
- .nested-post__expand-replies {
- margin-left: var(--nested-mobile-content-indent);
- }
-
.nested-post__content {
overflow-x: auto;
}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 95754059498..2c31b092080 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -4062,6 +4062,10 @@ en:
link: "Activity log"
title: "Topic activity log"
empty: "No topic activity to show."
+ context:
+ banner: "You are viewing a single thread from this topic."
+ view_full_topic: "View full topic"
+ view_parent_context: "View parent context"
topic:
filter_to:
one: "%{count} post in topic"
diff --git a/frontend/discourse/app/components/nested-replies-expand-button.gjs b/frontend/discourse/app/components/nested-replies-expand-button.gjs
index 4f5e17aac44..5232277f17b 100644
--- a/frontend/discourse/app/components/nested-replies-expand-button.gjs
+++ b/frontend/discourse/app/components/nested-replies-expand-button.gjs
@@ -14,9 +14,7 @@ export default class NestedRepliesExpandButton extends Component {
class="nested-post__expand-replies btn-flat"
...attributes
@action={{@onClick}}
- @disabled={{@disabled}}
@icon="discourse-circle-plus"
- @isLoading={{@isLoading}}
@translatedLabel={{this.label}}
/>
</template>
diff --git a/frontend/discourse/app/components/nested.gjs b/frontend/discourse/app/components/nested.gjs
index 2a16f94c0ae..c37ab702144 100644
--- a/frontend/discourse/app/components/nested.gjs
+++ b/frontend/discourse/app/components/nested.gjs
@@ -4,21 +4,16 @@ import { helper } from "@ember/component/helper";
import { fn } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
-import didInsert from "@ember/render-modifiers/modifiers/did-insert";
-import didUpdate from "@ember/render-modifiers/modifiers/did-update";
-import { cancel, next, schedule } from "@ember/runloop";
import { service } from "@ember/service";
import MoreTopics from "discourse/components/more-topics";
import PluginOutlet from "discourse/components/plugin-outlet";
+import PostAvatar from "discourse/components/post/avatar";
import lazyHash from "discourse/helpers/lazy-hash";
-import getURL, { withoutPrefix } from "discourse/lib/get-url";
-import DiscourseURL from "discourse/lib/url";
import PostStreamViewportTracker from "discourse/modifiers/post-stream-viewport-tracker";
import { and, gt, includes, not } from "discourse/truth-helpers";
import DButton from "discourse/ui-kit/d-button";
import DConditionalLoadingSpinner from "discourse/ui-kit/d-conditional-loading-spinner";
import DLoadMore from "discourse/ui-kit/d-load-more";
-import dAvatar from "discourse/ui-kit/helpers/d-avatar";
import dIcon from "discourse/ui-kit/helpers/d-icon";
import { i18n } from "discourse-i18n";
import NestedFloatingActions from "./nested/floating-actions";
@@ -35,16 +30,12 @@ const postExcerpt = helper(([post]) => {
return element.textContent?.replace(/\s+/g, " ").trim();
});
-// Depth is zero-based; depth 3 matches the server's root preload depth.
-const MOBILE_ROOT_VIEW_COLLAPSE_DEPTH = 3;
-
export default class Nested extends Component {
@service appEvents;
@service currentUser;
@service header;
@service screenTrack;
@service site;
- @service siteSettings;
@tracked cloakAbove = 0;
@tracked cloakBelow = 0;
@@ -52,26 +43,10 @@ export default class Nested extends Component {
@tracked focusedPath = [];
@tracked mobileReturnAnchor = null;
viewportTracker = new PostStreamViewportTracker();
- #initialFocusedPathKey = null;
- #focusedPathsByPostNumber = new Map();
- #scrollAttempts = 0;
- #maxScrollAttempts = 20;
- #nextTimer = null;
- #retryTimer = null;
- #highlightTimer = null;
- #lastScrollKey = null;
- #onPopstate = () => next(this, this.syncFocusFromURL);
constructor() {
super(...arguments);
- this.applyInitialFocusedPath();
- window.addEventListener("popstate", this.#onPopstate);
this.appEvents.on("keyboard:move-selection", this, this.maybeLoadMoreRoots);
- this.appEvents.on(
- "nested:scroll-to-target",
- this,
- this.forceScheduleTargetScroll
- );
this.appEvents.on(
"nested-replies:scroll-restored",
this,
@@ -86,20 +61,11 @@ export default class Nested extends Component {
this,
this.maybeLoadMoreRoots
);
- this.appEvents.off(
- "nested:scroll-to-target",
- this,
- this.forceScheduleTargetScroll
- );
this.appEvents.off(
"nested-replies:scroll-restored",
this,
this.clearMobileReturnAnchor
);
- cancel(this.#nextTimer);
- cancel(this.#retryTimer);
- clearTimeout(this.#highlightTimer);
- window.removeEventListener("popstate", this.#onPopstate);
this.viewportTracker.destroy();
}
@@ -122,42 +88,13 @@ export default class Nested extends Component {
}
get viewClass() {
- return [
- "nested-view",
- this.args.contextMode ? "nested-context-view" : null,
- this.isMobileFocused ? "-mobile-focused" : null,
- ]
- .filter(Boolean)
- .join(" ");
+ return this.isMobileFocused ? "nested-view -mobile-focused" : "nested-view";
}
get mobileFocusClass() {
return `nested-view__mobile-focus --${this.focusDirection}`;
}
- get collapseFromDepth() {
- if (this.args.collapseReplies) {
- if (this.args.contextMode) {
- return this.args.rootNodes?.[0]?.post?.post_number ===
- this.args.targetPostNumber
- ? 1
- : null;
- }
-
- if (this.isMobileFocused) {
- return this.focusedPath.length > 1 ? null : 1;
- }
-
- return 0;
- }
-
- if (this.site.mobileView) {
- return MOBILE_ROOT_VIEW_COLLAPSE_DEPTH;
- }
-
- return null;
- }
-
get rootScrollAnchor() {
return this.mobileReturnAnchor || this.args.scrollAnchor;
}
@@ -174,14 +111,6 @@ export default class Nested extends Component {
return this.focusedPath.slice(0, -1);
}
- get initialFocusedPathKey() {
- return this.#focusedPathKey(this.args.initialFocusedPath);
- }
-
- get targetScrollKey() {
- return `${this.args.targetPostNumber}:${this.args.rootNodes?.[0]?._renderKey}`;
- }
-
@action
setCloakingBoundaries(above, below) {
this.cloakAbove = above;
@@ -189,24 +118,18 @@ export default class Nested extends Component {
}
@action
- focusPath(path, returnAnchor) {
+ focusPath(path) {
if (!this.site.mobileView) {
return;
}
if (!this.isMobileFocused) {
- this.mobileReturnAnchor =
- returnAnchor ||
- this.findScrollAnchor() ||
- this.scrollAnchorForPath(path);
- this.args.saveScrollPosition?.(this.mobileReturnAnchor);
+ this.mobileReturnAnchor = this.scrollAnchorForPath(path);
}
this.focusDirection =
path.length >= this.focusedPath.length ? "forward" : "back";
this.focusedPath = path;
- this.#registerFocusedPath(path);
- this.#pushURLForFocusedPath(path);
}
@action
@@ -216,15 +139,9 @@ export default class Nested extends Component {
@action
clearFocus() {
- if (this.args.contextMode) {
- this.args.viewFullThread?.();
- return;
- }
-
this.focusDirection = "back";
this.mobileReturnAnchor ??= this.scrollAnchorForPath(this.focusedPath);
this.focusedPath = [];
- this.#replaceURLForFocusedPath([]);
}
@action
@@ -232,35 +149,6 @@ export default class Nested extends Component {
this.mobileReturnAnchor = null;
}
- @action
- captureScrollAnchor() {
- return this.findScrollAnchor();
- }
-
- findScrollAnchor() {
- const articles = document.querySelectorAll(
- ".nested-view__roots .nested-post [data-post-number]"
- );
- let best = null;
- let bestDistance = Infinity;
-
- for (const article of articles) {
- const postElement = article.closest(".nested-post") || article;
- const rect = postElement.getBoundingClientRect();
- const distance = Math.abs(rect.top);
- if (distance < bestDistance) {
- bestDistance = distance;
- best = {
- postNumber: Number(article.dataset.postNumber),
- offsetFromTop: rect.top,
- scrollY: window.scrollY,
- };
- }
- }
-
- return best;
- }
-
scrollAnchorForPath(path) {
const rootNode = path?.[0];
const postNumber = rootNode?.post?.post_number;
@@ -279,249 +167,12 @@ export default class Nested extends Component {
return {
postNumber,
offsetFromTop: element.getBoundingClientRect().top,
- scrollY: window.scrollY,
};
}
- @action
- scrollMobileFocusIntoContext(element) {
- if (!this.isMobileFocused || this.isDestroying || this.isDestroyed) {
- return;
- }
-
- const ancestorRows = element.querySelectorAll(
- ".nested-view__mobile-ancestor"
- );
- const target =
- ancestorRows[ancestorRows.length - 1] ||
- element.querySelector(".nested-view__mobile-focus-back");
- if (!target) {
- return;
- }
-
- const rect = target.getBoundingClientRect();
- window.scrollTo({
- top: window.scrollY + rect.top - this.#stickyHeaderBottom(),
- behavior: "auto",
- });
- }
-
- #stickyHeaderBottom() {
- const headerWrap = document.querySelector(".d-header-wrap");
- return Math.max(0, headerWrap?.getBoundingClientRect().bottom || 0);
- }
-
- @action
- applyInitialFocusedPath() {
- if (!this.site.mobileView) {
- return;
- }
-
- const key = this.initialFocusedPathKey;
-
- if (!this.args.initialFocusedPath?.length) {
- this.#initialFocusedPathKey = key;
- if (this.focusedPath.length > 0) {
- this.focusDirection = "back";
- this.focusedPath = [];
- }
- return;
- }
-
- if (key === this.#initialFocusedPathKey) {
- return;
- }
-
- this.#initialFocusedPathKey = key;
- this.focusDirection = "forward";
- this.focusedPath = this.args.initialFocusedPath;
- this.#registerFocusedPath(this.focusedPath);
- }
-
- #focusedPathKey(path) {
- return (path || [])
- .map((node) => `${node._renderKey || node.post?.id}:${node.post?.id}`)
- .join(":");
- }
-
- @action
- syncFocusFromURL() {
- if (this.isDestroying || this.isDestroyed || !this.site.mobileView) {
- return;
- }
-
- const postNumber = this.#postNumberFromCurrentURL();
- if (postNumber === undefined) {
- return;
- }
-
- if (!postNumber) {
- this.args.setFocusedPostNumber?.(null, []);
- if (this.focusedPath.length > 0) {
- this.focusDirection = "back";
- this.mobileReturnAnchor ??= this.scrollAnchorForPath(this.focusedPath);
- this.focusedPath = [];
- }
- return;
- }
-
- const path = this.#focusedPathsByPostNumber.get(postNumber);
- if (!path) {
- return;
- }
-
- this.args.setFocusedPostNumber?.(postNumber, path);
- this.focusDirection =
- path.length >= this.focusedPath.length ? "forward" : "back";
- this.focusedPath = path;
- }
-
- #pushURLForFocusedPath(path) {
- const postNumber = path.at(-1)?.post?.post_number || null;
- this.args.setFocusedPostNumber?.(postNumber, path);
- const url = this.#nestedURL(postNumber);
-
- if (this.#currentURLMatches(url)) {
- return;
- }
-
- DiscourseURL.pushState(url);
- }
-
- #replaceURLForFocusedPath(path) {
- const postNumber = path.at(-1)?.post?.post_number || null;
- this.args.setFocusedPostNumber?.(postNumber, path);
- const url = this.#nestedURL(postNumber);
-
- if (this.#currentURLMatches(url)) {
- return;
- }
-
- DiscourseURL.replaceState(url);
- }
-
- #registerFocusedPath(path) {
- path.forEach((node, index) => {
- const postNumber = node.post?.post_number;
- if (postNumber) {
- this.#focusedPathsByPostNumber.set(
- postNumber,
- path.slice(0, index + 1)
- );
- }
- });
- }
-
- #postNumberFromCurrentURL() {
- const path = withoutPrefix(window.location.pathname);
- const match = /^\/n\/[^/]+\/(\d+)(?:\/(\d+))?/.exec(path);
- if (!match || String(match[1]) !== String(this.args.topic.id)) {
- return undefined;
- }
-
- return match[2] ? Number(match[2]) : null;
- }
-
- #currentURLMatches(url) {
- const current = withoutPrefix(
- `${window.location.pathname}${window.location.search}`
- );
- const target = withoutPrefix(url);
-
- return current === target;
- }
-
- @action
- scheduleTargetScroll() {
- this.#scheduleTargetScroll();
- }
-
- @action
- forceScheduleTargetScroll() {
- this.#scheduleTargetScroll({ force: true });
- }
-
- #scheduleTargetScroll({ force = false } = {}) {
- if (!this.args.targetPostNumber || this.isMobileFocused) {
- return;
- }
-
- const scrollKey = this.targetScrollKey;
- if (!force && scrollKey === this.#lastScrollKey) {
- return;
- }
-
- this.#lastScrollKey = scrollKey;
- cancel(this.#nextTimer);
- cancel(this.#retryTimer);
- clearTimeout(this.#highlightTimer);
- this.#scrollAttempts = 0;
- this.#nextTimer = next(this, this.#scrollToTarget);
- }
-
- #scrollToTarget() {
- if (this.isDestroying || this.isDestroyed) {
- return;
- }
-
- const postNumber = this.args.targetPostNumber;
- const target = document.querySelector(
- `.nested-view [data-post-number="${postNumber}"]`
- );
-
- if (target) {
- const postEl = target.closest(".nested-post");
- if (postEl) {
- postEl.classList.add("nested-post--highlighted");
- this.#highlightTimer = setTimeout(
- () => postEl.classList.remove("nested-post--highlighted"),
- 2000
- );
- }
-
- const controls = document.querySelector(
- ".nested-view > .nested-view__controls"
- );
- const rect = target.getBoundingClientRect();
- window.scrollTo({
- top:
- window.scrollY +
- rect.top -
- (this.header.headerOffset || 0) -
- (controls?.offsetHeight || 0),
- behavior: "smooth",
- });
- } else if (this.#scrollAttempts < this.#maxScrollAttempts) {
- this.#scrollAttempts++;
- this.#retryTimer = schedule("afterRender", this, this.#scrollToTarget);
- }
- }
-
- #nestedURL(postNumber = null) {
- let path = `/n/${this.args.topic.slug}/${this.args.topic.id}`;
- if (postNumber) {
- path += `/${postNumber}`;
- }
-
- const params = new URLSearchParams();
- const defaultSort = this.siteSettings.nested_replies_default_sort || "top";
- if (this.args.sort && this.args.sort !== defaultSort) {
- params.set("sort", this.args.sort);
- }
- if (this.args.collapseReplies) {
- params.set("collapse_replies", "true");
- }
-
- const query = params.toString();
- return getURL(query ? `${path}?${query}` : path);
- }
-
<template>
<div
class={{this.viewClass}}
- {{didInsert this.scheduleTargetScroll}}
- {{didUpdate this.scheduleTargetScroll @targetPostNumber @rootNodes}}
- {{didUpdate this.applyInitialFocusedPath @initialFocusedPath}}
{{this.viewportTracker.setup
eyeline=false
headerOffset=this.header.headerOffset
@@ -551,11 +202,7 @@ export default class Nested extends Component {
/>
{{#if this.isMobileFocused}}
- <div
- class={{this.mobileFocusClass}}
- {{didInsert this.scrollMobileFocusIntoContext}}
- {{didUpdate this.scrollMobileFocusIntoContext this.focusedPath}}
- >
+ <div class={{this.mobileFocusClass}}>
<button
type="button"
class="nested-view__mobile-focus-back"
@@ -582,17 +229,7 @@ export default class Nested extends Component {
{{on "click" (fn this.returnToAncestor index)}}
>
{{dIcon "chevron-left"}}
- <span
- class="nested-view__mobile-ancestor-avatar"
- aria-hidden="true"
- >
- {{! PostAvatar renders a user link; keep this avatar non-interactive inside the ancestor button. }}
- {{dAvatar
- ancestorNode.post
- imageSize="small"
- hideTitle=true
- }}
- </span>
+ <PostAvatar @post={{ancestorNode.post}} @size="small" />
<span class="nested-view__mobile-ancestor-meta">
<span
class="nested-view__mobile-ancestor-username"
@@ -639,9 +276,8 @@ export default class Nested extends Component {
@getCloakingData={{this.viewportTracker.getCloakingData}}
@cloakAbove={{this.cloakAbove}}
@cloakBelow={{this.cloakBelow}}
- @collapseFromDepth={{this.collapseFromDepth}}
+ @collapseFromDepth={{if @collapseReplies 0}}
@focusPost={{this.focusPath}}
- @captureScrollAnchor={{this.captureScrollAnchor}}
@forceExpanded={{true}}
@multiSelect={{@multiSelect}}
@togglePostSelection={{@togglePostSelection}}
@@ -713,7 +349,7 @@ export default class Nested extends Component {
{{/if}}
<div class="nested-view__roots">
- {{#each @rootNodes key="_renderKey" as |node index|}}
+ {{#each @rootNodes key="post.id" as |node index|}}
<NestedPost
@post={{node.post}}
@children={{node.children}}
@@ -746,9 +382,8 @@ export default class Nested extends Component {
@getCloakingData={{this.viewportTracker.getCloakingData}}
@cloakAbove={{this.cloakAbove}}
@cloakBelow={{this.cloakBelow}}
- @collapseFromDepth={{this.collapseFromDepth}}
+ @collapseFromDepth={{if @collapseReplies 0}}
@focusPost={{this.focusPath}}
- @captureScrollAnchor={{this.captureScrollAnchor}}
@multiSelect={{@multiSelect}}
@togglePostSelection={{@togglePostSelection}}
@selectReplies={{@selectReplies}}
diff --git a/frontend/discourse/app/components/nested/context-view.gjs b/frontend/discourse/app/components/nested/context-view.gjs
new file mode 100644
index 00000000000..cca3a8fc1e9
--- /dev/null
+++ b/frontend/discourse/app/components/nested/context-view.gjs
@@ -0,0 +1,310 @@
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { array, fn } from "@ember/helper";
+import { action } from "@ember/object";
+import didInsert from "@ember/render-modifiers/modifiers/did-insert";
+import didUpdate from "@ember/render-modifiers/modifiers/did-update";
+import { cancel, next, schedule } from "@ember/runloop";
+import { service } from "@ember/service";
+import MoreTopics from "discourse/components/more-topics";
+import PluginOutlet from "discourse/components/plugin-outlet";
+import lazyHash from "discourse/helpers/lazy-hash";
+import PostStreamViewportTracker from "discourse/modifiers/post-stream-viewport-tracker";
+import { or } from "discourse/truth-helpers";
+import DButton from "discourse/ui-kit/d-button";
+import dIcon from "discourse/ui-kit/helpers/d-icon";
+import { i18n } from "discourse-i18n";
+import NestedFloatingActions from "./floating-actions";
+import NestedHeader from "./header";
+import NestedOp from "./op";
+import NestedPost from "./post";
+import NestedSortSelector from "./sort-selector";
+
+export default class NestedContextView extends Component {
+ @service appEvents;
+ @service header;
+ @service screenTrack;
+
+ @tracked cloakAbove = 0;
+ @tracked cloakBelow = 0;
+ viewportTracker = new PostStreamViewportTracker();
+ #scrollAttempts = 0;
+ #maxScrollAttempts = 20;
+ #destroyed = false;
+ #nextTimer = null;
+ #retryTimer = null;
+ #highlightTimer = null;
+ #lastScrollKey = null;
+
+ constructor() {
+ super(...arguments);
+ this.appEvents.on(
+ "nested:scroll-to-target",
+ this,
+ this.forceScheduleScroll
+ );
+ }
+
+ willDestroy() {
+ super.willDestroy(...arguments);
+ this.#destroyed = true;
+ cancel(this.#nextTimer);
+ cancel(this.#retryTimer);
+ clearTimeout(this.#highlightTimer);
+ this.appEvents.off(
+ "nested:scroll-to-target",
+ this,
+ this.forceScheduleScroll
+ );
+ this.viewportTracker.destroy();
+ }
+
+ // next() runs after RouteScrollManager's own next() callback, so our
+ // scroll wins. Fresh attempt counter per invocation.
+ @action
+ scheduleScroll() {
+ this.#scheduleScroll();
+ }
+
+ @action
+ forceScheduleScroll() {
+ this.#scheduleScroll({ force: true });
+ }
+
+ #scheduleScroll({ force = false } = {}) {
+ const scrollKey = this.#scrollKey;
+ if (!force && scrollKey === this.#lastScrollKey) {
+ return;
+ }
+
+ this.#lastScrollKey = scrollKey;
+ cancel(this.#nextTimer);
+ cancel(this.#retryTimer);
+ clearTimeout(this.#highlightTimer);
+ this.#scrollAttempts = 0;
+ this.#nextTimer = next(this, this.#scrollToTarget);
+ }
+
+ get #scrollKey() {
+ return `${this.args.targetPostNumber}:${this.args.contextChain?.post?.id}`;
+ }
+
+ #scrollToTarget() {
+ if (this.#destroyed) {
+ return;
+ }
+
+ const postNumber = this.args.targetPostNumber;
+ if (!postNumber) {
+ return;
+ }
+
+ const target = document.querySelector(
+ `.nested-context-view [data-post-number="${postNumber}"]`
+ );
+
+ if (target) {
+ const postEl = target.closest(".nested-post");
+ if (postEl) {
+ postEl.classList.add("nested-post--highlighted");
+ this.#highlightTimer = setTimeout(
+ () => postEl.classList.remove("nested-post--highlighted"),
+ 2000
+ );
+ }
+ const headerOffset = this.header.headerOffset || 0;
+ const banner = document.querySelector(".nested-context-view__banner");
+ const bannerHeight = banner ? banner.offsetHeight : 0;
+ const rect = target.getBoundingClientRect();
+ window.scrollTo({
+ top: window.scrollY + rect.top - headerOffset - bannerHeight,
+ behavior: "smooth",
+ });
+ } else if (this.#scrollAttempts < this.#maxScrollAttempts) {
+ // Target may not be in the DOM yet (async child rendering).
+ this.#scrollAttempts++;
+ this.#retryTimer = schedule("afterRender", this, this.#scrollToTarget);
+ }
+ }
+
+ @action
+ setCloakingBoundaries(above, below) {
+ this.cloakAbove = above;
+ this.cloakBelow = below;
+ }
+
+ // Only collapse when the chain is just the target — otherwise the target
+ // is the chain leaf and collapsing would hide the very thing the context
+ // view exists to surface.
+ get effectiveCollapseFromDepth() {
+ if (!this.args.collapseReplies) {
+ return null;
+ }
+ const chainRootPostNumber = this.args.contextChain?.post?.post_number;
+ if (chainRootPostNumber !== this.args.targetPostNumber) {
+ return null;
+ }
+ return 1;
+ }
+
+ <template>
+ <div
+ class="nested-view nested-context-view"
+ {{didInsert this.scheduleScroll}}
+ {{didUpdate this.scheduleScroll @targetPostNumber @contextChain.post.id}}
+ {{this.viewportTracker.setup
+ eyeline=false
+ headerOffset=this.header.headerOffset
+ screenTrack=this.screenTrack
+ setCloakingBoundaries=this.setCloakingBoundaries
+ }}
+ >
+ <NestedHeader
+ @topic={{@topic}}
+ @editingTopic={{@editingTopic}}
+ @buffered={{@buffered}}
+ @showCategoryChooser={{@showCategoryChooser}}
+ @canEditTags={{@canEditTags}}
+ @minimumRequiredTags={{@minimumRequiredTags}}
+ @finishedEditingTopic={{@finishedEditingTopic}}
+ @cancelEditingTopic={{@cancelEditingTopic}}
+ @topicCategoryChanged={{@topicCategoryChanged}}
+ @topicTagsChanged={{@topicTagsChanged}}
+ @startEditingTopic={{@startEditingTopic}}
+ />
+
+ <NestedOp
+ @post={{@opPost}}
+ @topic={{@topic}}
+ @editPost={{@editPost}}
+ @showHistory={{@showHistory}}
+ @changeNotice={{@changeNotice}}
+ @changePostOwner={{@changePostOwner}}
+ @grantBadge={{@grantBadge}}
+ @lockPost={{@lockPost}}
+ @unlockPost={{@unlockPost}}
+ @permanentlyDeletePost={{@permanentlyDeletePost}}
+ @rebakePost={{@rebakePost}}
+ @showPagePublish={{@showPagePublish}}
+ @togglePostType={{@togglePostType}}
+ @toggleWiki={{@toggleWiki}}
+ @unhidePost={{@unhidePost}}
+ @registerPost={{this.viewportTracker.registerPost}}
+ @multiSelect={{@multiSelect}}
+ @togglePostSelection={{@togglePostSelection}}
+ @selectReplies={{@selectReplies}}
+ @selectBelow={{@selectBelow}}
+ @postSelected={{@postSelected}}
+ />
+
+ <div class="nested-view__controls">
+ <div class="nested-view__controls-left">
+ <NestedSortSelector @current={{@sort}} @onChange={{@changeSort}} />
+ </div>
+
+ <div class="nested-view__controls-right">
+ {{#if @topic.has_activity_log}}
+ <DButton
+ class="btn-flat nested-view__activity-link"
+ @action={{@showActivityLog}}
+ @label="nested_replies.activity_log.link"
+ />
+ {{/if}}
+ </div>
+ </div>
+
+ <div class="nested-context-view__banner">
+ <span class="nested-context-view__banner-icon">{{dIcon
+ "nested-thread"
+ }}</span>
+ <span class="nested-context-view__banner-text">{{i18n
+ "nested_replies.context.banner"
+ }}</span>
+ <div class="nested-context-view__nav">
+ <DButton
+ class="btn-default btn-small nested-context-view__full-thread"
+ @action={{@viewFullThread}}
+ @icon="arrow-left"
+ @translatedLabel={{i18n "nested_replies.context.view_full_topic"}}
+ />
+ {{#if (or @contextNoAncestors @ancestorsTruncated)}}
+ <DButton
+ class="btn-default btn-small nested-context-view__parent-context"
+ @action={{@viewParentContext}}
+ @icon="arrow-up"
+ @translatedLabel={{i18n
+ "nested_replies.context.view_parent_context"
+ }}
+ />
+ {{/if}}
+ </div>
+ </div>
+
+ {{#if @contextChain}}
+ <div class="nested-context-view__chain">
+ {{! _renderKey changes every fetch — forces NestedPost rebuild
+ when chains share a root. See routes/nested.js. }}
+ {{#each (array @contextChain) key="_renderKey" as |chainRoot|}}
+ <NestedPost
+ @post={{chainRoot.post}}
+ @children={{chainRoot.children}}
+ @topic={{@topic}}
+ @depth={{0}}
+ @sort={{@sort}}
+ @replyToPost={{@replyToPost}}
+ @editPost={{@editPost}}
+ @deletePost={{@deletePost}}
+ @recoverPost={{@recoverPost}}
+ @showFlags={{@showFlags}}
+ @showHistory={{@showHistory}}
+ @changeNotice={{@changeNotice}}
+ @changePostOwner={{@changePostOwner}}
+ @grantBadge={{@grantBadge}}
+ @lockPost={{@lockPost}}
+ @unlockPost={{@unlockPost}}
+ @permanentlyDeletePost={{@permanentlyDeletePost}}
+ @rebakePost={{@rebakePost}}
+ @showPagePublish={{@showPagePublish}}
+ @togglePostType={{@togglePostType}}
+ @toggleWiki={{@toggleWiki}}
+ @unhidePost={{@unhidePost}}
+ @expansionState={{@expansionState}}
+ @fetchedChildrenCache={{@fetchedChildrenCache}}
+ @scrollAnchor={{@scrollAnchor}}
+ @registerPost={{this.viewportTracker.registerPost}}
+ @getCloakingData={{this.viewportTracker.getCloakingData}}
+ @cloakAbove={{this.cloakAbove}}
+ @cloakBelow={{this.cloakBelow}}
+ @collapseFromDepth={{this.effectiveCollapseFromDepth}}
+ @multiSelect={{@multiSelect}}
+ @togglePostSelection={{@togglePostSelection}}
+ @selectReplies={{@selectReplies}}
+ @selectBelow={{@selectBelow}}
+ @postSelected={{@postSelected}}
+ />
+ {{/each}}
+ </div>
+ {{/if}}
+
+ <PluginOutlet
+ @name="topic-above-suggested"
+ @connectorTagName="div"
+ @outletArgs={{lazyHash model=@topic}}
+ />
+
+ <MoreTopics @topic={{@topic}} />
+
+ <PluginOutlet
+ @name="topic-below-suggested"
+ @connectorTagName="div"
+ @outletArgs={{lazyHash model=@topic}}
+ />
+
+ <NestedFloatingActions
+ @topic={{@topic}}
+ @replyAction={{fn @replyToPost @opPost 0}}
+ />
+ </div>
+ </template>
+}
diff --git a/frontend/discourse/app/components/nested/post-children.gjs b/frontend/discourse/app/components/nested/post-children.gjs
index 8abb6a5d7c4..b71e4ecfdcb 100644
--- a/frontend/discourse/app/components/nested/post-children.gjs
+++ b/frontend/discourse/app/components/nested/post-children.gjs
@@ -85,11 +85,8 @@ export default class NestedPostChildren extends Component {
});
}
- _onChildCreated({ topicId, post, parentPostNumber }) {
- if (
- String(topicId) !== String(this.args.topic?.id) ||
- parentPostNumber !== this.args.parentPostNumber
- ) {
+ _onChildCreated({ post, parentPostNumber }) {
+ if (parentPostNumber !== this.args.parentPostNumber) {
return;
}
@@ -248,7 +245,6 @@ export default class NestedPostChildren extends Component {
@registerPost={{@registerPost}}
@collapseFromDepth={{@collapseFromDepth}}
@focusPost={{@focusPost}}
- @captureScrollAnchor={{@captureScrollAnchor}}
@multiSelect={{@multiSelect}}
@togglePostSelection={{@togglePostSelection}}
@selectReplies={{@selectReplies}}
diff --git a/frontend/discourse/app/components/nested/post.gjs b/frontend/discourse/app/components/nested/post.gjs
index 69d0c52869d..475d9fc9289 100644
--- a/frontend/discourse/app/components/nested/post.gjs
+++ b/frontend/discourse/app/components/nested/post.gjs
@@ -4,7 +4,6 @@ import { fn } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import { getOwner } from "@ember/owner";
-import { cancel, scheduleOnce } from "@ember/runloop";
import { service } from "@ember/service";
import { modifier } from "ember-modifier";
import ShareTopicModal from "discourse/components/modal/share-topic";
@@ -25,12 +24,10 @@ import { nativeShare } from "discourse/lib/pwa-utils";
import { clipboardCopy } from "discourse/lib/utilities";
import { and, not, or } from "discourse/truth-helpers";
import DButton from "discourse/ui-kit/d-button";
-import dAvatar from "discourse/ui-kit/helpers/d-avatar";
import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";
import dIcon from "discourse/ui-kit/helpers/d-icon";
import { i18n } from "discourse-i18n";
import nestedPostUrl from "../../lib/nested-post-url";
-import processNode from "../../lib/process-node";
import NestedPostChildren from "./post-children";
export default class NestedPost extends Component {
@@ -40,7 +37,6 @@ export default class NestedPost extends Component {
@service modal;
@service site;
@service siteSettings;
- @service store;
@tracked expanded;
@tracked lineHighlighted = false;
@@ -48,26 +44,20 @@ export default class NestedPost extends Component {
@tracked showDeletedContent = false;
@tracked showIgnoredContent = false;
@tracked loadingIgnoredContent = false;
- @tracked loadingReplies = false;
+
restoreScroll = modifier((element) => {
const anchor = this.args.scrollAnchor;
if (anchor?.postNumber !== this.args.post.post_number) {
return;
}
- if (Number.isFinite(anchor.scrollY)) {
- window.scrollTo(0, anchor.scrollY);
- } else {
- const rect = element.getBoundingClientRect();
- window.scrollTo(0, window.scrollY + rect.top - anchor.offsetFromTop);
- }
+ const rect = element.getBoundingClientRect();
+ window.scrollTo(0, window.scrollY + rect.top - anchor.offsetFromTop);
// Defer the event to avoid backtracking re-render errors during the render phase
Promise.resolve().then(() => {
this.appEvents.trigger("nested-replies:scroll-restored");
});
});
- #postRegistered = false;
- #postRegistrationTimer;
@tracked _childWasCreated = false;
@@ -103,44 +93,21 @@ export default class NestedPost extends Component {
this,
this._onChildCreated
);
- this.#postRegistrationTimer = scheduleOnce(
- "afterRender",
- this,
- this.#registerPost
- );
+ this.appEvents.trigger("nested-replies:post-registered", this.args.post);
}
willDestroy() {
super.willDestroy(...arguments);
- cancel(this.#postRegistrationTimer);
this.appEvents.off(
"nested-replies:child-created",
this,
this._onChildCreated
);
-
- if (this.#postRegistered) {
- this.appEvents.trigger(
- "nested-replies:post-unregistered",
- this.args.post
- );
- }
+ this.appEvents.trigger("nested-replies:post-unregistered", this.args.post);
}
- #registerPost() {
- if (this.isDestroying || this.isDestroyed) {
- return;
- }
-
- this.#postRegistered = true;
- this.appEvents.trigger("nested-replies:post-registered", this.args.post);
- }
-
- _onChildCreated({ topicId, post: childPost, parentPostNumber, isOwnPost }) {
- if (
- String(topicId) !== String(this.args.topic?.id) ||
- parentPostNumber !== this.args.post.post_number
- ) {
+ _onChildCreated({ parentPostNumber }) {
+ if (parentPostNumber !== this.args.post.post_number) {
return;
}
@@ -157,10 +124,6 @@ export default class NestedPost extends Component {
collapsed: false,
});
}
-
- if (isOwnPost && this.mobileFocusEnabled) {
- this.args.focusPost(this.childPathWithNewChild(childPost));
- }
}
get isRoot() {
@@ -253,40 +216,10 @@ export default class NestedPost extends Component {
];
}
- childPathWithChildren(children) {
- return [
- ...(this.args.path || []),
- { post: this.args.post, children: children || [] },
- ];
- }
-
- childPathWithNewChild(childPost) {
- const children = this.args.children || [];
- const hasChild = children.some(
- (node) =>
- node.post?.id === childPost?.id ||
- node.post?.post_number === childPost?.post_number
- );
-
- return [
- ...(this.args.path || []),
- {
- post: this.args.post,
- children: hasChild
- ? children
- : [{ post: childPost, children: [] }, ...children],
- },
- ];
- }
-
get mobileFocusEnabled() {
return this.site.mobileView && this.args.focusPost;
}
- get childDepth() {
- return this.args.depth + 1;
- }
-
get effectiveExpanded() {
return this.args.forceExpanded || this.expanded;
}
@@ -322,10 +255,6 @@ export default class NestedPost extends Component {
}
get depthLineLabel() {
- if (this.site.mobileView && !this.args.forceExpanded) {
- return i18n("nested_replies.collapse");
- }
-
if (this.depthLineCollapsed) {
return this.expandLabel;
}
@@ -359,84 +288,10 @@ export default class NestedPost extends Component {
});
}
- collapsePost() {
- if (this.hasReplies) {
- this.expanded = false;
- }
-
- this.collapsed = true;
- this.lineHighlighted = false;
- this.args.expansionState?.set(this.args.post.post_number, {
- expanded: this.expanded,
- collapsed: this.collapsed,
- });
- }
-
- async childrenForMobileFocus() {
- const cached = this.args.fetchedChildrenCache?.get(
- this.args.post.post_number
- );
- if (cached) {
- return cached.childNodes;
- }
-
- if ((this.args.children?.length ?? 0) > 0 || !this.hasReplies) {
- return this.args.children || [];
- }
-
- this.loadingReplies = true;
- try {
- const data = await ajax(
- `/n/${this.args.topic.slug}/${this.args.topic.id}/children/${this.args.post.post_number}.json?sort=${this.args.sort || "top"}&depth=${this.childDepth}`
- );
- if (this.isDestroying || this.isDestroyed) {
- return null;
- }
-
- const childNodes = (data.children || []).map((child) =>
- processNode(this.store, this.args.topic, child)
- );
- this.args.fetchedChildrenCache?.set(this.args.post.post_number, {
- childNodes,
- page: data.page,
- hasMore: data.has_more || false,
- fetchedFromServer: true,
- });
- return childNodes;
- } catch (e) {
- if (!(this.isDestroying || this.isDestroyed)) {
- popupAjaxError(e);
- }
- return null;
- } finally {
- if (!(this.isDestroying || this.isDestroyed)) {
- this.loadingReplies = false;
- }
- }
- }
-
@action
- async handleReplies() {
- if (this.loadingReplies) {
- return;
- }
-
+ handleReplies() {
if (this.mobileFocusEnabled) {
- const returnAnchor = this.args.captureScrollAnchor?.();
- const children = await this.childrenForMobileFocus();
- if (children && !(this.isDestroying || this.isDestroyed)) {
- this.args.focusPost(this.childPathWithChildren(children), returnAnchor);
- }
- return;
- }
-
- this.toggleExpanded();
- }
-
- @action
- handleDepthLine() {
- if (this.site.mobileView && !this.args.forceExpanded) {
- this.collapsePost();
+ this.args.focusPost(this.childPath);
return;
}
@@ -624,7 +479,7 @@ export default class NestedPost extends Component {
this.depthLineCollapsed "nested-post__depth-line--collapsed"
)
}}
- {{on "click" this.handleDepthLine}}
+ {{on "click" this.toggleExpanded}}
{{on "mouseenter" this.highlightLine}}
{{on "mouseleave" this.unhighlightLine}}
aria-label={{this.depthLineLabel}}
@@ -645,18 +500,6 @@ export default class NestedPost extends Component {
data-post-number={{@post.post_number}}
{{on "click" this.toggleExpanded}}
>
- {{#if this.isMobile}}
- <span class="nested-post__collapsed-avatar" aria-hidden="true">
- {{#if this.isDeletedPlaceholder}}
- {{dIcon "trash-can"}}
- {{else if this.renderIgnoredPlaceholder}}
- {{dIcon "far-eye-slash"}}
- {{else}}
- {{! PostAvatar renders a user link; keep this avatar non-interactive inside the collapsed button. }}
- {{dAvatar @post imageSize="small" hideTitle=true}}
- {{/if}}
- </span>
- {{/if}}
{{dIcon "discourse-circle-plus"}}
{{#if this.isDeletedPlaceholder}}
<span class="nested-post__collapsed-username">{{i18n
@@ -825,8 +668,6 @@ export default class NestedPost extends Component {
{{#if this.showExpandRepliesButton}}
<NestedRepliesExpandButton
@replyCount={{this.replyCount}}
- @disabled={{this.loadingReplies}}
- @isLoading={{this.loadingReplies}}
@onClick={{this.handleReplies}}
/>
{{/if}}
@@ -895,7 +736,6 @@ export default class NestedPost extends Component {
@registerPost={{@registerPost}}
@collapseFromDepth={{@collapseFromDepth}}
@focusPost={{@focusPost}}
- @captureScrollAnchor={{@captureScrollAnchor}}
@multiSelect={{@multiSelect}}
@togglePostSelection={{@togglePostSelection}}
@selectReplies={{@selectReplies}}
diff --git a/frontend/discourse/app/controllers/nested.js b/frontend/discourse/app/controllers/nested.js
index 4a0c5bf84a9..885c066176f 100644
--- a/frontend/discourse/app/controllers/nested.js
+++ b/frontend/discourse/app/controllers/nested.js
@@ -40,7 +40,6 @@ export default class NestedController extends Controller {
@tracked postNumber;
@tracked contextMode = false;
@tracked contextChain = null;
- @tracked initialFocusedPath = [];
@tracked targetPostNumber = null;
@tracked contextNoAncestors = false;
@tracked ancestorsTruncated = false;
@@ -65,7 +64,7 @@ export default class NestedController extends Controller {
// Populated by NestedPostChildren on every mutation, read on restoration.
fetchedChildrenCache = new Map();
- // Scroll anchor for cache restoration: { postNumber, offsetFromTop, scrollY? }
+ // Scroll anchor for cache restoration: { postNumber, offsetFromTop }
scrollAnchor = null;
quoteState = new QuoteState();
@@ -113,10 +112,6 @@ export default class NestedController extends Controller {
return this.#topicController.selectedPostsCount;
}
- get newRootPostCount() {
- return this.contextMode ? 0 : this.newRootPostIds.length;
- }
-
get canSelectAll() {
return this.#nestedSelectablePostIds().some(
(id) => !this.#topicController.selectedPostIds.includes(id)
@@ -310,55 +305,6 @@ export default class NestedController extends Controller {
});
}
- @action
- setFocusedPostNumber(postNumber, focusedPath = []) {
- this.postNumber = postNumber;
- this.targetPostNumber = postNumber;
- this.initialFocusedPath = focusedPath;
- }
-
- @action
- saveScrollPosition(scrollAnchor) {
- this.saveToCache(scrollAnchor);
- }
-
- saveToCache(scrollAnchor) {
- if (!this.topic) {
- return;
- }
-
- const cacheKey = this.nestedViewCache.buildKey(this.topic.id, {
- sort: this.sort,
- post_number: this.postNumber,
- context: this.contextNoAncestors ? 0 : undefined,
- });
-
- this.nestedViewCache.save(cacheKey, {
- modelData: {
- topic: this.topic,
- opPost: this.opPost,
- rootNodes: this.rootNodes,
- page: this.page,
- hasMoreRoots: this.hasMoreRoots,
- sort: this.sort,
- messageBusLastId: this.messageBusLastId,
- pinnedPostIds: this.pinnedPostIds,
- postNumber: this.postNumber,
- contextMode: this.contextMode,
- contextChain: this.contextChain,
- initialFocusedPath: this.initialFocusedPath,
- targetPostNumber: this.targetPostNumber,
- contextNoAncestors: this.contextNoAncestors,
- ancestorsTruncated: this.ancestorsTruncated,
- topAncestorPostNumber: this.topAncestorPostNumber,
- newRootPostIds: this.newRootPostIds,
- },
- expansionState: new Map(this.expansionState),
- fetchedChildrenCache: new Map(this.fetchedChildrenCache),
- scrollAnchor,
- });
- }
-
@action
viewParentContext() {
if (this.ancestorsTruncated && this.topAncestorPostNumber) {
@@ -667,22 +613,13 @@ export default class NestedController extends Controller {
}
#onPostRegistered(post) {
- const topicId = this.topic?.id;
- if (
- post?.post_number != null &&
- topicId != null &&
- String(post.topic?.id) === String(topicId)
- ) {
- this.topic?.postStream?.storePost(post);
+ if (post?.post_number != null) {
this.postRegistry.set(post.post_number, post);
}
}
#onPostUnregistered(post) {
- if (
- post?.post_number != null &&
- this.postRegistry.get(post.post_number) === post
- ) {
+ if (post?.post_number != null) {
this.postRegistry.delete(post.post_number);
}
}
@@ -730,25 +667,20 @@ export default class NestedController extends Controller {
return;
}
+ const { post } = this.#processNode({ ...postData, children: [] });
+
const replyTo = postData.reply_to_post_number;
const isRoot = !replyTo || replyTo === 1;
if (isRoot) {
- if (this.contextMode) {
- return;
- }
-
- const node = this.#processNode({ ...postData, children: [] });
if (data.user_id === this.currentUser?.id) {
- this.rootNodes = [node, ...this.rootNodes];
+ this.rootNodes = [{ post, children: [] }, ...this.rootNodes];
} else {
this.newRootPostIds = [...this.newRootPostIds, data.id];
}
} else {
- const node = this.#processNode({ ...postData, children: [] });
this.appEvents.trigger("nested-replies:child-created", {
- topicId,
- post: node.post,
+ post,
parentPostNumber: replyTo,
isOwnPost: data.user_id === this.currentUser?.id,
});
@@ -831,11 +763,6 @@ export default class NestedController extends Controller {
@action
async loadNewRoots() {
- if (this.contextMode) {
- this.newRootPostIds = [];
- return;
- }
-
const ids = [...this.newRootPostIds];
this.newRootPostIds = [];
diff --git a/frontend/discourse/app/lib/process-node.js b/frontend/discourse/app/lib/process-node.js
index 017e39b87d8..5b8d46d45e9 100644
--- a/frontend/discourse/app/lib/process-node.js
+++ b/frontend/discourse/app/lib/process-node.js
@@ -35,5 +35,5 @@ export default function processNode(store, topic, nodeData) {
const children = (nodeData.children || []).map((child) =>
processNode(store, topic, child)
);
- return { post, children, _renderKey: nodeData._renderKey || post.id };
+ return { post, children };
}
diff --git a/frontend/discourse/app/routes/nested.js b/frontend/discourse/app/routes/nested.js
index 1bb0c9758c9..0da60f04fe0 100644
--- a/frontend/discourse/app/routes/nested.js
+++ b/frontend/discourse/app/routes/nested.js
@@ -41,8 +41,6 @@ export default class NestedRoute extends DiscourseRoute {
async model(params) {
const { topic_id, slug, post_number } = params;
- this._teardownCurrentTopic(topic_id);
-
const sort =
params.sort || this.siteSettings.nested_replies_default_sort || "top";
@@ -151,7 +149,6 @@ export default class NestedRoute extends DiscourseRoute {
this._resetTopicControllerBulkSelection();
controller.unsubscribe();
this.screenTrack.stop();
- controller.topic = null;
}
@action
@@ -202,20 +199,34 @@ export default class NestedRoute extends DiscourseRoute {
return;
}
- controller.saveToCache(this._findScrollAnchor());
- }
-
- _teardownCurrentTopic(nextTopicId) {
- const controller = this.controllerFor("nested");
- const currentTopicId = controller.topic?.id;
-
- if (!currentTopicId || String(currentTopicId) === String(nextTopicId)) {
- return;
- }
+ const cacheKey = this.nestedViewCache.buildKey(controller.topic.id, {
+ sort: controller.sort,
+ post_number: controller.postNumber,
+ context: controller.contextNoAncestors ? 0 : undefined,
+ });
- this._saveToCache(controller);
- controller.unsubscribe();
- this.screenTrack.stop();
+ this.nestedViewCache.save(cacheKey, {
+ modelData: {
+ topic: controller.topic,
+ opPost: controller.opPost,
+ rootNodes: controller.rootNodes,
+ page: controller.page,
+ hasMoreRoots: controller.hasMoreRoots,
+ sort: controller.sort,
+ messageBusLastId: controller.messageBusLastId,
+ pinnedPostIds: controller.pinnedPostIds,
+ postNumber: controller.postNumber,
+ contextMode: controller.contextMode,
+ contextChain: controller.contextChain,
+ targetPostNumber: controller.targetPostNumber,
+ contextNoAncestors: controller.contextNoAncestors,
+ ancestorsTruncated: controller.ancestorsTruncated,
+ topAncestorPostNumber: controller.topAncestorPostNumber,
+ },
+ expansionState: new Map(controller.expansionState),
+ fetchedChildrenCache: new Map(controller.fetchedChildrenCache),
+ scrollAnchor: this._findScrollAnchor(),
+ });
}
_findScrollAnchor() {
@@ -287,7 +298,6 @@ export default class NestedRoute extends DiscourseRoute {
postNumber: params.post_number ? Number(params.post_number) : null,
contextMode: false,
contextChain: null,
- initialFocusedPath: [],
targetPostNumber: null,
contextNoAncestors: false,
ancestorsTruncated: false,
@@ -330,14 +340,8 @@ export default class NestedRoute extends DiscourseRoute {
// Nest ancestors outermost-first so target ends up as the chain leaf.
let chainTip = targetNode;
- const focusedPath = [targetNode];
for (let i = ancestors.length - 1; i >= 0; i--) {
- chainTip = {
- post: ancestors[i],
- children: [chainTip],
- _renderKey: ancestors[i].id,
- };
- focusedPath.unshift(chainTip);
+ chainTip = { post: ancestors[i], children: [chainTip] };
}
// Force full NestedPost rebuild on every fetch: NestedPostChildren reads
@@ -355,13 +359,12 @@ export default class NestedRoute extends DiscourseRoute {
postNumber: Number(params.post_number),
contextMode: true,
contextChain: chainTip,
- initialFocusedPath: focusedPath,
targetPostNumber: Number(params.post_number),
contextNoAncestors: noAncestors,
ancestorsTruncated: data.ancestors_truncated || false,
topAncestorPostNumber:
ancestors.length > 0 ? ancestors[0].post_number : null,
- rootNodes: [chainTip],
+ rootNodes: [],
page: 0,
hasMoreRoots: false,
newRootPostIds: [],
diff --git a/frontend/discourse/app/templates/nested.gjs b/frontend/discourse/app/templates/nested.gjs
index 11069765424..d81f52852ef 100644
--- a/frontend/discourse/app/templates/nested.gjs
+++ b/frontend/discourse/app/templates/nested.gjs
@@ -1,40 +1,90 @@
-import { array } from "@ember/helper";
import Nested from "discourse/components/nested";
+import NestedContextView from "discourse/components/nested/context-view";
import PostTextSelection from "discourse/components/post-text-selection";
import SelectedPosts from "discourse/components/selected-posts";
export default <template>
- {{#each (array @controller.topic) key="id" as |topic|}}
- <PostTextSelection
- @quoteState={{@controller.quoteState}}
- @selectText={{@controller.selectText}}
- @buildQuoteMarkdown={{@controller.buildQuoteMarkdown}}
- @editPost={{@controller.editPost}}
- @topic={{topic}}
- />
+ <PostTextSelection
+ @quoteState={{@controller.quoteState}}
+ @selectText={{@controller.selectText}}
+ @buildQuoteMarkdown={{@controller.buildQuoteMarkdown}}
+ @editPost={{@controller.editPost}}
+ @topic={{@controller.topic}}
+ />
- <div
- class="selected-posts nested-view__selected-posts
- {{unless @controller.multiSelect 'hidden'}}"
- >
- <SelectedPosts
- @selectedPostsCount={{@controller.selectedPostsCount}}
- @canSelectAll={{@controller.canSelectAll}}
- @canDeselectAll={{@controller.canDeselectAll}}
- @canDeleteSelected={{@controller.canDeleteSelected}}
- @canMergeTopic={{@controller.canMergeTopic}}
- @canChangeOwner={{@controller.canChangeOwner}}
- @canMergePosts={{@controller.canMergePosts}}
- @toggleMultiSelect={{@controller.toggleMultiSelect}}
- @mergePosts={{@controller.mergePosts}}
- @deleteSelected={{@controller.deleteSelected}}
- @deselectAll={{@controller.deselectAll}}
- @selectAll={{@controller.selectAll}}
- />
- </div>
+ <div
+ class="selected-posts nested-view__selected-posts
+ {{unless @controller.multiSelect 'hidden'}}"
+ >
+ <SelectedPosts
+ @selectedPostsCount={{@controller.selectedPostsCount}}
+ @canSelectAll={{@controller.canSelectAll}}
+ @canDeselectAll={{@controller.canDeselectAll}}
+ @canDeleteSelected={{@controller.canDeleteSelected}}
+ @canMergeTopic={{@controller.canMergeTopic}}
+ @canChangeOwner={{@controller.canChangeOwner}}
+ @canMergePosts={{@controller.canMergePosts}}
+ @toggleMultiSelect={{@controller.toggleMultiSelect}}
+ @mergePosts={{@controller.mergePosts}}
+ @deleteSelected={{@controller.deleteSelected}}
+ @deselectAll={{@controller.deselectAll}}
+ @selectAll={{@controller.selectAll}}
+ />
+ </div>
+ {{#if @controller.contextMode}}
+ <NestedContextView
+ @topic={{@controller.topic}}
+ @opPost={{@controller.opPost}}
+ @contextChain={{@controller.contextChain}}
+ @targetPostNumber={{@controller.targetPostNumber}}
+ @contextNoAncestors={{@controller.contextNoAncestors}}
+ @ancestorsTruncated={{@controller.ancestorsTruncated}}
+ @sort={{@controller.sort}}
+ @changeSort={{@controller.changeSort}}
+ @viewFullThread={{@controller.viewFullThread}}
+ @viewParentContext={{@controller.viewParentContext}}
+ @replyToPost={{@controller.replyToPost}}
+ @editPost={{@controller.editPost}}
+ @deletePost={{@controller.deletePost}}
+ @recoverPost={{@controller.recoverPost}}
+ @showFlags={{@controller.showFlags}}
+ @showHistory={{@controller.showHistory}}
+ @changeNotice={{@controller.changeNotice}}
+ @changePostOwner={{@controller.changePostOwner}}
+ @grantBadge={{@controller.grantBadge}}
+ @lockPost={{@controller.lockPost}}
+ @unlockPost={{@controller.unlockPost}}
+ @permanentlyDeletePost={{@controller.permanentlyDeletePost}}
+ @rebakePost={{@controller.rebakePost}}
+ @showPagePublish={{@controller.showPagePublish}}
+ @togglePostType={{@controller.togglePostType}}
+ @toggleWiki={{@controller.toggleWiki}}
+ @unhidePost={{@controller.unhidePost}}
+ @editingTopic={{@controller.editingTopic}}
+ @startEditingTopic={{@controller.startEditingTopic}}
+ @cancelEditingTopic={{@controller.cancelEditingTopic}}
+ @finishedEditingTopic={{@controller.finishedEditingTopic}}
+ @showCategoryChooser={{@controller.showCategoryChooser}}
+ @canEditTags={{@controller.canEditTags}}
+ @buffered={{@controller.buffered}}
+ @topicCategoryChanged={{@controller.topicCategoryChanged}}
+ @topicTagsChanged={{@controller.topicTagsChanged}}
+ @minimumRequiredTags={{@controller.minimumRequiredTags}}
+ @expansionState={{@controller.expansionState}}
+ @fetchedChildrenCache={{@controller.fetchedChildrenCache}}
+ @scrollAnchor={{@controller.scrollAnchor}}
+ @showActivityLog={{@controller.showActivityLog}}
+ @collapseReplies={{@controller.collapseReplies}}
+ @multiSelect={{@controller.multiSelect}}
+ @togglePostSelection={{@controller.togglePostSelection}}
+ @selectReplies={{@controller.selectReplies}}
+ @selectBelow={{@controller.selectBelow}}
+ @postSelected={{@controller.postSelected}}
+ />
+ {{else}}
<Nested
- @topic={{topic}}
+ @topic={{@controller.topic}}
@opPost={{@controller.opPost}}
@rootNodes={{@controller.rootNodes}}
@hasMoreRoots={{@controller.hasMoreRoots}}
@@ -60,14 +110,8 @@ export default <template>
@toggleWiki={{@controller.toggleWiki}}
@unhidePost={{@controller.unhidePost}}
@postNumber={{@controller.postNumber}}
- @contextMode={{@controller.contextMode}}
- @targetPostNumber={{@controller.targetPostNumber}}
- @initialFocusedPath={{@controller.initialFocusedPath}}
- @setFocusedPostNumber={{@controller.setFocusedPostNumber}}
- @saveScrollPosition={{@controller.saveScrollPosition}}
- @viewFullThread={{@controller.viewFullThread}}
@pinnedPostIds={{@controller.pinnedPostIds}}
- @newRootPostCount={{@controller.newRootPostCount}}
+ @newRootPostCount={{@controller.newRootPostIds.length}}
@loadNewRoots={{@controller.loadNewRoots}}
@editingTopic={{@controller.editingTopic}}
@startEditingTopic={{@controller.startEditingTopic}}
@@ -90,5 +134,5 @@ export default <template>
@selectBelow={{@controller.selectBelow}}
@postSelected={{@controller.postSelected}}
/>
- {{/each}}
+ {{/if}}
</template>
diff --git a/frontend/discourse/tests/integration/components/nested/post-test.gjs b/frontend/discourse/tests/integration/components/nested/post-test.gjs
index 9e3b82842f0..638bde6f09c 100644
--- a/frontend/discourse/tests/integration/components/nested/post-test.gjs
+++ b/frontend/discourse/tests/integration/components/nested/post-test.gjs
@@ -2,10 +2,8 @@ import { getOwner } from "@ember/owner";
import { click, render } from "@ember/test-helpers";
import { modifier } from "ember-modifier";
import { module, test } from "qunit";
-import sinon from "sinon";
import NestedPost from "discourse/components/nested/post";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
-import pretender, { response } from "discourse/tests/helpers/create-pretender";
import { i18n } from "discourse-i18n";
const noop = () => {};
@@ -18,7 +16,7 @@ function renderComponent(context) {
@post={{context.post}}
@children={{context.children}}
@topic={{context.topic}}
- @depth={{context.depth}}
+ @depth={{0}}
@path={{context.path}}
@sort="top"
@replyToPost={{noop}}
@@ -40,9 +38,7 @@ function renderComponent(context) {
@unhidePost={{noop}}
@expansionState={{context.expansionState}}
@fetchedChildrenCache={{context.fetchedChildrenCache}}
- @focusPost={{context.focusPost}}
@registerPost={{registerPost}}
- @collapseFromDepth={{context.collapseFromDepth}}
@multiSelect={{context.multiSelect}}
@togglePostSelection={{context.togglePostSelection}}
@selectReplies={{context.selectReplies}}
@@ -66,8 +62,6 @@ module("Integration | Component | Nested | Post", function (hooks) {
});
this.path = [];
this.children = [];
- this.depth = 0;
- this.collapseFromDepth = null;
this.expansionState = new Map();
this.fetchedChildrenCache = new Map();
this.multiSelect = false;
@@ -90,10 +84,6 @@ module("Integration | Component | Nested | Post", function (hooks) {
});
});
- hooks.afterEach(function () {
- sinon.restore();
- });
-
test("leaf posts can be collapsed from the depth line", async function (assert) {
await renderComponent(this);
@@ -142,134 +132,6 @@ module("Integration | Component | Nested | Post", function (hooks) {
);
});
- test("mobile collapsed posts keep an avatar in the collapsed bar", async function (assert) {
- const site = getOwner(this).lookup("service:site");
- sinon.stub(site, "mobileView").value(true);
-
- await renderComponent(this);
- await click(".nested-post__depth-line");
-
- assert.dom(".nested-post__article").doesNotExist("collapses the post body");
- assert
- .dom(".nested-post__collapsed-avatar .avatar")
- .exists("renders the post avatar in the mobile collapsed bar");
- });
-
- test("post registration can update post topic", async function (assert) {
- const appEvents = getOwner(this).lookup("service:app-events");
- const updatedTopic = this.store.createRecord("topic", {
- id: 99,
- slug: "updated-topic",
- user_id: 1,
- });
- let registered = false;
- const register = (post) => {
- post.topic;
- post.topic = updatedTopic;
- registered = true;
- };
-
- appEvents.on("nested-replies:post-registered", this, register);
-
- try {
- await renderComponent(this);
-
- assert.true(registered, "registers the post");
- assert.strictEqual(this.post.topic, updatedTopic, "updates the topic");
- } finally {
- appEvents.off("nested-replies:post-registered", this, register);
- }
- });
-
- test("mobile focus waits for unloaded children before focusing", async function (assert) {
- const site = getOwner(this).lookup("service:site");
- sinon.stub(site, "mobileView").value(true);
-
- this.post.set("direct_reply_count", 1);
- this.post.set("total_descendant_count", 1);
-
- let focusedPath;
- let requestedChildren = false;
- this.focusPost = (path) => {
- focusedPath = path;
- };
-
- pretender.get("/n/nested-topic/1/children/2.json", (request) => {
- requestedChildren = true;
- assert.strictEqual(
- focusedPath,
- undefined,
- "does not enter focused mode before children are fetched"
- );
- assert.strictEqual(request.queryParams.sort, "top");
- assert.strictEqual(request.queryParams.depth, "1");
-
- return response({
- children: [
- {
- id: 3,
- post_number: 3,
- topic_id: 1,
- user_id: 3,
- username: "child-user",
- avatar_template: "/letter_avatar_proxy/v4/letter/c/25/48.png",
- cooked: "<p>Child post</p>",
- created_at: "2026-01-01T00:00:00.000Z",
- actions_summary: [],
- direct_reply_count: 0,
- total_descendant_count: 0,
- children: [],
- },
- ],
- has_more: false,
- page: 0,
- });
- });
-
- await renderComponent(this);
- await click(".nested-post__expand-replies");
-
- assert.true(requestedChildren, "fetches the missing children first");
- assert.strictEqual(focusedPath.length, 1, "focuses after the request");
- assert.strictEqual(
- focusedPath[0].children[0].post.post_number,
- 3,
- "hydrates the focused path with the fetched child"
- );
- assert.strictEqual(
- this.fetchedChildrenCache.get(2).childNodes,
- focusedPath[0].children,
- "stores the fetched children in the shared cache"
- );
- });
-
- test("reply counts below the mobile depth cap do not preload missing children", async function (assert) {
- this.depth = 3;
- this.collapseFromDepth = 4;
- this.post.set("direct_reply_count", 1);
- this.post.set("total_descendant_count", 1);
-
- pretender.get("/n/nested-topic/1/children/2.json", () => {
- assert.step("requested children");
-
- return response({
- children: [],
- has_more: false,
- page: 0,
- });
- });
-
- await renderComponent(this);
-
- assert
- .dom(".nested-post__expand-replies")
- .exists("shows the explicit expansion affordance");
- assert
- .dom(".nested-post-children")
- .doesNotExist("does not mount the child loader");
- assert.verifySteps([], "does not request children while rendering");
- });
-
test("renders multi-select controls", async function (assert) {
let selectedPost;
this.multiSelect = true;
diff --git a/frontend/discourse/tests/unit/controllers/nested-test.js b/frontend/discourse/tests/unit/controllers/nested-test.js
deleted file mode 100644
index c80d6766e20..00000000000
--- a/frontend/discourse/tests/unit/controllers/nested-test.js
+++ /dev/null
@@ -1,329 +0,0 @@
-import { settled } from "@ember/test-helpers";
-import { setupTest } from "ember-qunit";
-import { module, test } from "qunit";
-import pretender, { response } from "discourse/tests/helpers/create-pretender";
-import { logIn } from "discourse/tests/helpers/qunit-helpers";
-
-module("Unit | Controller | nested", function (hooks) {
- setupTest(hooks);
-
- hooks.beforeEach(function () {
- this.currentUser = logIn(this.owner);
- this.appEvents = this.owner.lookup("service:app-events");
- this.controller = this.owner.lookup("controller:nested");
- this.nestedViewCache = this.owner.lookup("service:nested-view-cache");
- this.store = this.owner.lookup("service:store");
- });
-
- hooks.afterEach(function () {
- this.controller.unsubscribe();
- this.controller.topic = null;
- this.controller.contextMode = false;
- this.controller.rootNodes = [];
- this.controller.newRootPostIds = [];
- });
-
- function buildTopic(store, id) {
- return store.createRecord("topic", {
- id,
- slug: `topic-${id}`,
- });
- }
-
- function buildPost(store, topic, id, postNumber) {
- const post = store.createRecord("post", {
- id,
- post_number: postNumber,
- topic,
- });
- post.topic = topic;
- return post;
- }
-
- test("post registry events are scoped to the current topic", function (assert) {
- const previousTopic = buildTopic(this.store, 509);
- const currentTopic = buildTopic(this.store, 724);
- const previousPost = buildPost(this.store, previousTopic, 1001, 2);
- const currentPost = buildPost(this.store, currentTopic, 2001, 2);
-
- this.controller.topic = currentTopic;
- this.controller.subscribe();
-
- this.appEvents.trigger("nested-replies:post-registered", previousPost);
-
- assert.false(
- this.controller.postRegistry.has(2),
- "ignores post registration from a previous topic"
- );
-
- this.appEvents.trigger("nested-replies:post-registered", currentPost);
- this.appEvents.trigger("nested-replies:post-unregistered", previousPost);
-
- assert.strictEqual(
- this.controller.postRegistry.get(2),
- currentPost,
- "does not unregister the current topic post for a stale same-number post"
- );
-
- this.appEvents.trigger("nested-replies:post-unregistered", currentPost);
-
- assert.false(
- this.controller.postRegistry.has(2),
- "unregisters the matching current topic post"
- );
- });
-
- test("own root message inserts a processed root node", async function (assert) {
- const topic = buildTopic(this.store, 724);
- const postId = 2001;
-
- this.controller.topic = topic;
- this.controller.rootNodes = [];
- this.controller.newRootPostIds = [];
-
- pretender.get(`/posts/${postId}.json`, () =>
- response({
- id: postId,
- post_number: 2,
- topic_id: topic.id,
- user_id: this.currentUser.id,
- username: this.currentUser.username,
- avatar_template: this.currentUser.avatar_template,
- cooked: "<p>Own root reply</p>",
- created_at: "2026-01-01T00:00:00.000Z",
- actions_summary: [],
- direct_reply_count: 0,
- total_descendant_count: 0,
- reply_to_post_number: null,
- children: [],
- })
- );
-
- this.controller._onMessage(
- { type: "created", id: postId, user_id: this.currentUser.id },
- null,
- 123
- );
- await settled();
-
- assert.strictEqual(
- this.controller.rootNodes.length,
- 1,
- "inserts the own root reply immediately"
- );
- assert.strictEqual(
- this.controller.rootNodes[0].post.id,
- postId,
- "stores the fetched post"
- );
- assert.strictEqual(
- this.controller.rootNodes[0]._renderKey,
- postId,
- "preserves the processed node render key"
- );
- assert.deepEqual(
- this.controller.newRootPostIds,
- [],
- "does not queue own root replies behind the new replies banner"
- );
- });
-
- test("context view ignores live root replies", async function (assert) {
- const topic = buildTopic(this.store, 724);
- const contextRoot = buildPost(this.store, topic, 1001, 2);
- const ownPostId = 2001;
- const otherPostId = 2002;
-
- this.controller.topic = topic;
- this.controller.contextMode = true;
- this.controller.rootNodes = [{ post: contextRoot, children: [] }];
- this.controller.newRootPostIds = [];
-
- pretender.get(`/posts/${ownPostId}.json`, () =>
- response({
- id: ownPostId,
- post_number: 3,
- topic_id: topic.id,
- user_id: this.currentUser.id,
- username: this.currentUser.username,
- avatar_template: this.currentUser.avatar_template,
- cooked: "<p>Own root reply</p>",
- created_at: "2026-01-01T00:00:00.000Z",
- actions_summary: [],
- direct_reply_count: 0,
- total_descendant_count: 0,
- reply_to_post_number: null,
- children: [],
- })
- );
- pretender.get(`/posts/${otherPostId}.json`, () =>
- response({
- id: otherPostId,
- post_number: 4,
- topic_id: topic.id,
- user_id: 999,
- username: "other-user",
- avatar_template: "/letter_avatar_proxy/v4/letter/o/25/48.png",
- cooked: "<p>Other root reply</p>",
- created_at: "2026-01-01T00:00:00.000Z",
- actions_summary: [],
- direct_reply_count: 0,
- total_descendant_count: 0,
- reply_to_post_number: null,
- children: [],
- })
- );
-
- this.controller._onMessage(
- { type: "created", id: ownPostId, user_id: this.currentUser.id },
- null,
- 123
- );
- this.controller._onMessage(
- { type: "created", id: otherPostId, user_id: 999 },
- null,
- 124
- );
- await settled();
-
- assert.deepEqual(
- this.controller.rootNodes.map((node) => node.post.id),
- [contextRoot.id],
- "keeps the context branch isolated from new root replies"
- );
- assert.deepEqual(
- this.controller.newRootPostIds,
- [],
- "does not show the new root replies banner in context mode"
- );
- assert.strictEqual(
- this.controller.newRootPostCount,
- 0,
- "reports no visible new root replies in context mode"
- );
- });
-
- test("context view ignores queued new root replies", async function (assert) {
- const topic = buildTopic(this.store, 724);
- const contextRoot = buildPost(this.store, topic, 1001, 2);
-
- this.controller.topic = topic;
- this.controller.contextMode = true;
- this.controller.rootNodes = [{ post: contextRoot, children: [] }];
- this.controller.newRootPostIds = [2001];
-
- assert.strictEqual(
- this.controller.newRootPostCount,
- 0,
- "hides queued root replies while rendering context"
- );
-
- await this.controller.loadNewRoots();
-
- assert.deepEqual(
- this.controller.newRootPostIds,
- [],
- "clears stale queued roots without loading them"
- );
- assert.deepEqual(
- this.controller.rootNodes.map((node) => node.post.id),
- [contextRoot.id],
- "keeps the context branch unchanged"
- );
- });
-
- test("context view still dispatches live child replies", async function (assert) {
- const topic = buildTopic(this.store, 724);
- const childPostId = 2001;
- let childCreatedEvent;
- const captureChildCreated = (event) => {
- childCreatedEvent = event;
- };
-
- this.controller.topic = topic;
- this.controller.contextMode = true;
- this.appEvents.on(
- "nested-replies:child-created",
- this,
- captureChildCreated
- );
-
- pretender.get(`/posts/${childPostId}.json`, () =>
- response({
- id: childPostId,
- post_number: 3,
- topic_id: topic.id,
- user_id: this.currentUser.id,
- username: this.currentUser.username,
- avatar_template: this.currentUser.avatar_template,
- cooked: "<p>Child reply</p>",
- created_at: "2026-01-01T00:00:00.000Z",
- actions_summary: [],
- direct_reply_count: 0,
- total_descendant_count: 0,
- reply_to_post_number: 2,
- children: [],
- })
- );
-
- try {
- this.controller._onMessage(
- { type: "created", id: childPostId, user_id: this.currentUser.id },
- null,
- 123
- );
- await settled();
-
- assert.strictEqual(
- childCreatedEvent?.topicId,
- topic.id,
- "dispatches the update for the current topic"
- );
- assert.strictEqual(
- childCreatedEvent?.parentPostNumber,
- 2,
- "targets the parent post"
- );
- assert.strictEqual(
- childCreatedEvent?.post.id,
- childPostId,
- "passes the fetched child post"
- );
- assert.true(childCreatedEvent?.isOwnPost, "marks own replies");
- } finally {
- this.appEvents.off(
- "nested-replies:child-created",
- this,
- captureChildCreated
- );
- }
- });
-
- test("focused post cache entries include the mobile focused path", function (assert) {
- const topic = buildTopic(this.store, 724);
- const focusedPost = buildPost(this.store, topic, 2001, 2);
- const focusedPath = [{ post: focusedPost, children: [] }];
-
- this.controller.topic = topic;
- this.controller.sort = "top";
- this.controller.rootNodes = focusedPath;
-
- this.controller.setFocusedPostNumber(2, focusedPath);
- this.controller.saveToCache({ postNumber: 2, offsetFromTop: 80 });
-
- const cached = this.nestedViewCache.get(
- this.nestedViewCache.buildKey(topic.id, { sort: "top", post_number: 2 })
- );
-
- assert.strictEqual(
- cached.modelData.initialFocusedPath,
- focusedPath,
- "keeps enough focused-path state to restore the mobile drill-down URL"
- );
- assert.strictEqual(
- cached.modelData.postNumber,
- 2,
- "stores the post URL cache entry under the focused post number"
- );
- });
-});
diff --git a/frontend/discourse/tests/unit/routes/nested-test.js b/frontend/discourse/tests/unit/routes/nested-test.js
index 3fa15a955d1..badadc00771 100644
--- a/frontend/discourse/tests/unit/routes/nested-test.js
+++ b/frontend/discourse/tests/unit/routes/nested-test.js
@@ -1,15 +1,10 @@
import EmberObject from "@ember/object";
import { setupTest } from "ember-qunit";
import { module, test } from "qunit";
-import sinon from "sinon";
module("Unit | Route | nested", function (hooks) {
setupTest(hooks);
- hooks.afterEach(function () {
- sinon.restore();
- });
-
test("contributes topic title tokens", function (assert) {
const route = this.owner.lookup("route:nested");
const category = EmberObject.create({
@@ -34,41 +29,6 @@ module("Unit | Route | nested", function (hooks) {
);
});
- test("tears down the active nested topic before loading a different topic", function (assert) {
- const route = this.owner.lookup("route:nested");
- const controller = this.owner.lookup("controller:nested");
- controller.topic = { id: 509 };
-
- const saveToCache = sinon.stub(route, "_saveToCache");
- const unsubscribe = sinon.stub(controller, "unsubscribe");
- const stopScreenTrack = sinon.stub(route.screenTrack, "stop");
-
- route._teardownCurrentTopic(724);
-
- assert.true(
- saveToCache.calledOnceWith(controller),
- "stores the current topic state before replacing it"
- );
- assert.true(unsubscribe.calledOnce, "unsubscribes from the old topic");
- assert.true(stopScreenTrack.calledOnce, "stops old topic screen tracking");
- });
-
- test("keeps the active nested topic subscribed when the topic id is unchanged", function (assert) {
- const route = this.owner.lookup("route:nested");
- const controller = this.owner.lookup("controller:nested");
- controller.topic = { id: 509 };
-
- const saveToCache = sinon.stub(route, "_saveToCache");
- const unsubscribe = sinon.stub(controller, "unsubscribe");
- const stopScreenTrack = sinon.stub(route.screenTrack, "stop");
-
- route._teardownCurrentTopic("509");
-
- assert.false(saveToCache.called, "does not cache in-topic refreshes");
- assert.false(unsubscribe.called, "keeps the active subscription");
- assert.false(stopScreenTrack.called, "keeps screen tracking active");
- });
-
test("selected-post route actions open modals through the topic route", function (assert) {
const nestedRoute = this.owner.lookup("route:nested");
const topicRoute = this.owner.lookup("route:topic");
@@ -209,48 +169,4 @@ module("Unit | Route | nested", function (hooks) {
"clears stale selected post ids"
);
});
-
- test("deactivate clears stale nested topic before a later entry", function (assert) {
- const nestedRoute = this.owner.lookup("route:nested");
- const nestedController = this.owner.lookup("controller:nested");
- const saveToCache = sinon.stub(nestedRoute, "_saveToCache");
- const unsubscribe = sinon.stub(nestedController, "unsubscribe");
- const stopScreenTrack = sinon.stub(nestedRoute.screenTrack, "stop");
-
- nestedRoute.controller = nestedController;
- nestedController.topic = { id: 509 };
-
- nestedRoute.deactivate();
-
- assert.true(
- saveToCache.calledOnceWith(nestedController),
- "stores the active nested topic before leaving"
- );
- assert.true(unsubscribe.calledOnce, "unsubscribes from the active topic");
- assert.true(stopScreenTrack.calledOnce, "stops screen tracking");
- assert.strictEqual(
- nestedController.topic,
- null,
- "clears the inactive topic reference"
- );
-
- saveToCache.resetHistory();
- unsubscribe.resetHistory();
- stopScreenTrack.resetHistory();
-
- nestedRoute._teardownCurrentTopic(724);
-
- assert.false(
- saveToCache.called,
- "does not overwrite cache from a non-nested page"
- );
- assert.false(
- unsubscribe.called,
- "does not unsubscribe an already inactive nested topic"
- );
- assert.false(
- stopScreenTrack.called,
- "does not stop screen tracking a second time"
- );
- });
});
diff --git a/spec/system/nested_collapse_replies_spec.rb b/spec/system/nested_collapse_replies_spec.rb
index 29fed0ef1e2..b1afd465e81 100644
--- a/spec/system/nested_collapse_replies_spec.rb
+++ b/spec/system/nested_collapse_replies_spec.rb
@@ -68,7 +68,7 @@ RSpec.describe "Nested view collapse_replies URL param" do
# replies behind a button). When the target is *below* the chain
# root, applying collapseFromDepth=1 would hide the target itself,
# defeating the whole point of the context view. The
- # collapseFromDepth getter in nested.gjs ignores
+ # effectiveCollapseFromDepth getter in context-view.gjs ignores
# collapse_replies in that case.
it "ignores collapse_replies and shows the target when the chain has ancestors" do
page.visit("/n/#{topic.slug}/#{topic.id}/#{reply_to_reply.post_number}?collapse_replies=true")
diff --git a/spec/system/nested_context_view_spec.rb b/spec/system/nested_context_view_spec.rb
index da04563aabf..4d5443c1153 100644
--- a/spec/system/nested_context_view_spec.rb
+++ b/spec/system/nested_context_view_spec.rb
@@ -42,10 +42,18 @@ RSpec.describe "Nested context view" do
expect(nested_view).to have_post(chain_posts[2])
end
- it "marks direct post URLs as context routes" do
+ it "shows 'View full thread' link but not 'View parent context'" do
nested_view.visit_nested_context(topic, post_number: chain_posts[2].post_number)
- expect(nested_view).to have_context_view
+ expect(nested_view).to have_view_full_thread_link
+ expect(nested_view).to have_no_view_parent_context_link
+ end
+
+ it "does not show 'View parent context' for a direct reply to the OP" do
+ nested_view.visit_nested_context(topic, post_number: chain_posts[0].post_number)
+
+ expect(nested_view).to have_view_full_thread_link
+ expect(nested_view).to have_no_view_parent_context_link
end
it "highlights the target post" do
@@ -66,11 +74,49 @@ RSpec.describe "Nested context view" do
expect(nested_view).to have_no_post(chain_posts[2])
end
- it "keeps the target as the branch root" do
+ it "shows 'View parent context' link" do
+ nested_view.visit_nested_context(topic, post_number: chain_posts[3].post_number, context: 0)
+
+ expect(nested_view).to have_view_parent_context_link
+ end
+
+ it "clicking 'View parent context' shows full ancestor chain" do
+ nested_view.visit_nested_context(topic, post_number: chain_posts[3].post_number, context: 0)
+ nested_view.click_view_parent_context
+
+ expect(nested_view).to have_context_view
+ expect(nested_view).to have_post(chain_posts[0])
+ expect(nested_view).to have_post(chain_posts[1])
+ expect(nested_view).to have_post(chain_posts[2])
+ expect(nested_view).to have_post(chain_posts[3])
+ end
+ end
+
+ describe "navigation" do
+ it "clicking 'View full thread' returns to root view" do
+ nested_view.visit_nested_context(topic, post_number: chain_posts[2].post_number)
+ nested_view.click_view_full_thread
+
+ expect(nested_view).to have_nested_view
+ expect(nested_view).to have_no_css(".nested-context-view")
+ end
+
+ it "full navigation flow: context=0 → parent context → full thread" do
nested_view.visit_nested_context(topic, post_number: chain_posts[3].post_number, context: 0)
expect(nested_view).to have_no_post(chain_posts[0])
expect(nested_view).to have_post_at_depth(chain_posts[3], depth: 0)
+
+ nested_view.click_view_parent_context
+
+ expect(nested_view).to have_post(chain_posts[0])
+ expect(nested_view).to have_post(chain_posts[3])
+
+ nested_view.click_view_full_thread
+
+ expect(nested_view).to have_nested_view
+ expect(nested_view).to have_no_css(".nested-context-view")
+ expect(nested_view).to have_root_post(chain_posts[0])
end
end
@@ -104,17 +150,32 @@ RSpec.describe "Nested context view" do
expect(nested_view).to have_no_post(deep_chain[1])
end
- it "marks truncated contexts as targeted nested views" do
+ it "shows 'View parent context' when ancestors are truncated" do
+ nested_view.visit_nested_context(topic, post_number: deep_chain[12].post_number)
+
+ expect(nested_view).to have_view_parent_context_link
+ end
+
+ it "clicking 'View parent context' shifts window up to topmost ancestor" do
nested_view.visit_nested_context(topic, post_number: deep_chain[12].post_number)
+ nested_view.click_view_parent_context
expect(nested_view).to have_context_view
+ expect(nested_view).to have_post(deep_chain[2])
+ expect(nested_view).to have_no_post(deep_chain[12])
end
- it "context=0 starts at the target even when ancestors would be truncated" do
+ it "navigating up from context=0 shows windowed ancestors" do
nested_view.visit_nested_context(topic, post_number: deep_chain[12].post_number, context: 0)
expect(nested_view).to have_post_at_depth(deep_chain[12], depth: 0)
expect(nested_view).to have_no_post(deep_chain[11])
+
+ nested_view.click_view_parent_context
+
+ expect(nested_view).to have_post(deep_chain[12])
+ expect(nested_view).to have_post(deep_chain[3])
+ expect(nested_view).to have_view_parent_context_link
end
end
diff --git a/spec/system/nested_replying_spec.rb b/spec/system/nested_replying_spec.rb
index 20a6901b710..fe1c0f72575 100644
--- a/spec/system/nested_replying_spec.rb
+++ b/spec/system/nested_replying_spec.rb
@@ -122,22 +122,6 @@ RSpec.describe "Nested view replying" do
expect(nested_view).to have_no_collapsed_bar_for(root_reply)
expect(nested_view).to have_children_visible_for(root_reply)
end
-
- it "takes the user into the parent branch on mobile", mobile: true do
- nested_view.visit_nested(topic)
- expect(nested_view).to have_post(child_reply)
-
- nested_view.click_reply_on_post(root_reply)
- expect(composer).to be_opened
-
- composer.fill_content("Reply from mobile")
- composer.submit
-
- expect(composer).to be_closed
- expect(nested_view).to have_mobile_focus
- expect(nested_view).to have_post(child_reply)
- expect(nested_view).to have_post_text("Reply from mobile")
- end
end
describe "replying to a post with no existing children" do
diff --git a/spec/system/nested_view_spec.rb b/spec/system/nested_view_spec.rb
index 0e8e593f16a..3a3d212be72 100644
--- a/spec/system/nested_view_spec.rb
+++ b/spec/system/nested_view_spec.rb
@@ -266,188 +266,32 @@ RSpec.describe "Nested view" do
)
end
- fab!(:great_grandchild_reply) do
- Fabricate(
- :post,
- topic: topic,
- user: Fabricate(:user),
- raw: "A great-grandchild post",
- reply_to_post_number: grandchild_reply.post_number,
- )
- end
-
- fab!(:fifth_level_reply) do
- Fabricate(
- :post,
- topic: topic,
- user: Fabricate(:user),
- raw: "A fifth-level post",
- reply_to_post_number: great_grandchild_reply.post_number,
- )
- end
-
- fab!(:sixth_level_reply) do
- Fabricate(
- :post,
- topic: topic,
- user: Fabricate(:user),
- raw: "A sixth-level post",
- reply_to_post_number: fifth_level_reply.post_number,
- )
- end
-
it "lets the user drill into reply branches without leaving the topic", mobile: true do
- nested_view.visit_nested(topic)
- nested_path = %r{/n/#{topic.slug}/#{topic.id}}
+ nested_view.visit_nested(topic, query: "collapse_replies=true")
+ nested_path = %r{/n/#{topic.slug}/#{topic.id}\?collapse_replies=true}
- expect(nested_view).to have_post(child_reply)
- expect(nested_view).to have_post(grandchild_reply)
- expect(nested_view).to have_post(great_grandchild_reply)
- expect(nested_view).to have_replies_toggle_for(great_grandchild_reply)
- expect(nested_view).to have_no_post(fifth_level_reply)
+ nested_view.scroll_post_near_top(root_reply)
+ root_reply_top = nested_view.post_viewport_top(root_reply)
- nested_view.click_replies_toggle(great_grandchild_reply)
+ nested_view.click_replies_toggle(root_reply)
- expect(page).to have_current_path(
- %r{/n/#{topic.slug}/#{topic.id}/#{great_grandchild_reply.post_number}},
- )
+ expect(page).to have_current_path(nested_path)
expect(nested_view).to have_mobile_focus
- expect(nested_view).to have_mobile_ancestor(root_reply)
- expect(nested_view).to have_mobile_ancestor(child_reply)
- expect(nested_view).to have_mobile_ancestor(grandchild_reply)
- expect(nested_view).to have_post(fifth_level_reply)
- expect(nested_view).to have_post(sixth_level_reply)
+ expect(nested_view).to have_post(child_reply)
expect(nested_view).to have_no_root_post(sibling_root_reply)
- nested_view.click_mobile_focus_back
+ nested_view.click_replies_toggle(child_reply)
expect(page).to have_current_path(nested_path)
- expect(nested_view).to have_no_mobile_focus
- expect(nested_view).to have_root_post(sibling_root_reply)
- end
-
- it "browser back returns from a focused branch to the full nested topic and restores scroll",
- mobile: true do
- child_reply.update!(raw: "A child post\n\n#{("Scrollable child content.\n\n" * 30).strip}")
- child_reply.rebake!
-
- page.visit("/latest")
- nested_view.visit_nested(topic)
- nested_view.scroll_post_near_top(great_grandchild_reply)
-
- previous_scroll_y = nested_view.trigger_replies_toggle(great_grandchild_reply)
- expect(page).to have_current_path(
- %r{/n/#{topic.slug}/#{topic.id}/#{great_grandchild_reply.post_number}},
- )
- expect(nested_view).to have_mobile_focus
-
- page.go_back
-
- expect(page).to have_current_path(%r{/n/#{topic.slug}/#{topic.id}$})
- expect(nested_view).to have_no_mobile_focus
- try_until_success(reason: "scroll anchor restores after focused view closes") do
- expect(page.evaluate_script("window.scrollY")).to be_within(250).of(previous_scroll_y)
- end
- end
-
- it "uses the focused branch UI for direct post URLs", mobile: true do
- nested_view.visit_nested_context(topic, post_number: grandchild_reply.post_number)
-
- expect(page).to have_current_path(
- %r{/n/#{topic.slug}/#{topic.id}/#{grandchild_reply.post_number}},
- )
- expect(nested_view).to have_mobile_focus
- expect(nested_view).to have_mobile_ancestor(root_reply)
- expect(nested_view).to have_mobile_ancestor(child_reply)
- expect(nested_view).to have_post(great_grandchild_reply)
-
- nested_view.click_mobile_ancestor(child_reply)
-
- expect(page).to have_current_path(%r{/n/#{topic.slug}/#{topic.id}/#{child_reply.post_number}})
expect(nested_view).to have_mobile_ancestor(root_reply)
- expect(nested_view).to have_no_mobile_ancestor(child_reply)
- end
-
- it "returns from direct post URLs to all replies", mobile: true do
- nested_view.visit_nested_context(topic, post_number: grandchild_reply.post_number)
-
- expect(nested_view).to have_mobile_focus
+ expect(nested_view).to have_post(grandchild_reply)
nested_view.click_mobile_focus_back
- expect(page).to have_current_path(%r{/n/#{topic.slug}/#{topic.id}(?:\?.*)?$})
- expect(nested_view).to have_no_mobile_focus
- expect(nested_view).to have_root_post(root_reply)
- expect(nested_view).to have_root_post(sibling_root_reply)
- end
-
- it "does not open the user card when tapping a focused path avatar", mobile: true do
- nested_view.visit_nested_context(topic, post_number: grandchild_reply.post_number)
-
- expect(nested_view).to have_mobile_ancestor(child_reply)
- expect(nested_view).to have_no_mobile_ancestor_user_card_trigger(child_reply)
-
- nested_view.click_mobile_ancestor_avatar(child_reply)
-
- expect(page).to have_current_path(%r{/n/#{topic.slug}/#{topic.id}/#{child_reply.post_number}})
- expect(nested_view).to have_no_mobile_ancestor(child_reply)
- expect(page).to have_no_css(".user-card.show")
- end
-
- it "brings the parent branch control into view after opening hidden replies", mobile: true do
- sixth_level_reply.update!(
- raw: "A sixth-level post\n\n#{("More focused branch content.\n\n" * 30).strip}",
- )
- sixth_level_reply.rebake!
-
- nested_view.visit_nested(topic)
- nested_view.scroll_post_near_top(great_grandchild_reply)
-
- nested_view.click_replies_toggle(great_grandchild_reply)
-
- expect(nested_view).to have_mobile_focus
- try_until_success(reason: "focused view scroll runs after render") do
- expect(nested_view.mobile_ancestor_viewport_top(grandchild_reply)).to be_between(
- -1,
- 120,
- ).inclusive
- end
- end
-
- it "collapses a root branch from the depth line", mobile: true do
- nested_view.visit_nested(topic)
-
- nested_view.click_depth_line(root_reply)
-
- expect(nested_view).to have_no_mobile_focus
- expect(nested_view).to have_collapsed_bar_for(root_reply)
- expect(nested_view).to have_no_children_visible_for(root_reply)
- expect(nested_view).to have_root_post(sibling_root_reply)
- end
-
- it "collapses a child branch from the depth line", mobile: true do
- nested_view.visit_nested(topic)
-
- nested_view.click_depth_line(child_reply)
-
- expect(nested_view).to have_no_mobile_focus
- expect(nested_view).to have_collapsed_bar_for(child_reply)
- expect(nested_view).to have_no_children_visible_for(child_reply)
- expect(nested_view).to have_root_post(sibling_root_reply)
- end
-
- it "collapses a branch with hidden replies from the depth line", mobile: true do
- nested_view.visit_nested(topic)
-
- expect(nested_view).to have_replies_toggle_for(great_grandchild_reply)
- expect(nested_view).to have_no_post(fifth_level_reply)
-
- nested_view.click_depth_line(great_grandchild_reply)
-
+ expect(page).to have_current_path(nested_path)
expect(nested_view).to have_no_mobile_focus
- expect(nested_view).to have_collapsed_bar_for(great_grandchild_reply)
- expect(nested_view).to have_no_post(fifth_level_reply)
expect(nested_view).to have_root_post(sibling_root_reply)
+ expect(nested_view.post_viewport_top(root_reply)).to be_within(5).of(root_reply_top)
end
end
diff --git a/spec/system/page_objects/pages/nested_view.rb b/spec/system/page_objects/pages/nested_view.rb
index 93fa9582989..d22cbfe38e6 100644
--- a/spec/system/page_objects/pages/nested_view.rb
+++ b/spec/system/page_objects/pages/nested_view.rb
@@ -62,6 +62,18 @@ module PageObjects
has_css?(".nested-context-view")
end
+ def has_view_full_thread_link?
+ has_css?(".nested-context-view__full-thread")
+ end
+
+ def has_view_parent_context_link?
+ has_css?(".nested-context-view__parent-context")
+ end
+
+ def has_no_view_parent_context_link?
+ has_no_css?(".nested-context-view__parent-context")
+ end
+
# ── Post assertions ───────────────────────────────────────────
def has_post_at_depth?(post, depth:)
@@ -72,10 +84,6 @@ module PageObjects
has_css?("[data-post-number='#{post.post_number}']")
end
- def has_post_text?(text)
- has_css?(".nested-post__article", text: text)
- end
-
def has_no_post?(post)
has_no_css?("[data-post-number='#{post.post_number}']")
end
@@ -139,10 +147,6 @@ module PageObjects
has_no_css?("[data-test-nested-mobile-ancestor='#{post.post_number}']")
end
- def has_no_mobile_ancestor_user_card_trigger?(post)
- has_no_css?("[data-test-nested-mobile-ancestor='#{post.post_number}'] [data-user-card]")
- end
-
def post_viewport_top(post)
page.evaluate_script(<<~JS)
document
@@ -153,15 +157,6 @@ module PageObjects
JS
end
- def mobile_ancestor_viewport_top(post)
- page.evaluate_script(<<~JS)
- document
- .querySelector("[data-test-nested-mobile-ancestor='#{post.post_number}']")
- .getBoundingClientRect()
- .top
- JS
- end
-
def has_depth_line_for?(post)
has_css?(depth_line_selector(post))
end
@@ -336,24 +331,6 @@ module PageObjects
self
end
- def trigger_replies_toggle(post)
- page.evaluate_script(<<~JS)
- (() => {
- const button = document.querySelector(
- "[data-post-number='#{post.post_number}'] .nested-post__expand-replies"
- );
- document
- .querySelectorAll(".nested-view__roots .nested-post [data-post-number]")
- .forEach((article) =>
- (article.closest(".nested-post") || article).getBoundingClientRect()
- );
- const scrollY = window.scrollY;
- button.click();
- return scrollY;
- })()
- JS
- end
-
def scroll_post_near_top(post, offset: 80)
page.execute_script(<<~JS)
const post = document.querySelector("[data-post-number='#{post.post_number}']");
@@ -395,15 +372,18 @@ module PageObjects
self
end
- def click_mobile_ancestor_avatar(post)
- find(
- "[data-test-nested-mobile-ancestor='#{post.post_number}'] .nested-view__mobile-ancestor-avatar",
- ).click
+ def click_mobile_focus_back
+ find(".nested-view__mobile-focus-back").click
self
end
- def click_mobile_focus_back
- find(".nested-view__mobile-focus-back").click
+ def click_view_full_thread
+ find(".nested-context-view__full-thread").click
+ self
+ end
+
+ def click_view_parent_context
+ find(".nested-context-view__parent-context").click
self
end