FIX: Fully re-render ads when navigating between pages (#188)

In the past, the ad plugin relied on two side-effects to achieve this behaviour:

1. Components being fully destroyed/rendered when navigating between pages. This stopped working when Discourse core moved to the more efficient 'loading slider' UI

2. The `listLoading` argument. This was an implementation detail of the old discovery routing infrastructure. Core recently overhauled this and removed the `listLoading` argument, because loading is now handled properly by the Ember router.

Instead of these two properties, we can use the `currentRoute` property of Ember's router service to trigger changes when navigating between pages. A common `{{#each` trick is used to fully destroy/re-render components even if the ad network is unchanged.
This commit is contained in:
David Taylor
2023-11-07 21:12:30 +00:00
committed by GitHub
parent 5ad841de0b
commit c88bb59d81
11 changed files with 35 additions and 85 deletions
+11 -1
View File
@@ -2,6 +2,7 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import {
acceptance,
query,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
@@ -69,12 +70,21 @@ acceptance("House Ads", function (needs) {
assert
.dom(".h-topic-list")
.exists({ count: 1 }, "it should render ad above topic list");
const originalTopAdElement = query(".h-topic-list");
await visit("/latest");
assert
.dom(".h-between-topic-list")
.exists({ count: 5 }, "it should render 5 ads between topics");
await visit("/top");
const newTopAdElement = query(".h-topic-list");
assert.notStrictEqual(
originalTopAdElement,
newTopAdElement,
"ad is fully re-rendered when changing pages"
);
await visit("/t/28830");
assert