fix(ajax): show the reference skeleton on every load-more surface
Clicking 加载更多 in the 多栏目文章 widget showed no skeleton at all — the
list simply stayed still until the response arrived, then the new cards
appeared. The homepage stream, archives and comments already had a working
skeleton; the widget's AJAX load goes through a different client and never
found its loader.
Root cause was DOM placement, not visibility: ContentRenderer emitted
.post_ajax_loader as a *sibling* of .widget-ajaxpager, while the widget REST
client resolves it with container.querySelector('.post_ajax_loader'). The
node existed but could never match, so .is-loading was never added and the
skeleton stayed display:none. Inactive tab panes had the same shape, and the
direct-load branch of ajaxpager() emitted no loader at all.
Changes, all following the reference theme's post_ajax() contract in
zibll/js/main.js (beforeSend anchors the loader to the end of the list;
success only hides it, never removes it):
- ContentRenderer: nest the loader inside .widget-ajaxpager for both the
direct-load and inactive-tab branches, and drop the sibling append.
- widgets/frontend.js: anchorLoader() moves the loader to the end of the
list before .ajax-pag on every request; appended cards are inserted before
it; a replace preserves the node instead of wiping it with innerHTML; a
fallback loader is created when the DOM has none; loadItems() now returns
its promise; drop the unreachable is-loading auto-load branch.
- Message centre, user-home panels and the search page switch from spinner /
opacity feedback to the same .posts-item-shaped skeleton, so all AJAX
surfaces share one loading contract.
- Remove the second, never-wired skeleton system (.aksrt-skeleton-* in
core-ui.css) and the dead spinner stylesheets/rules (skeleton.css,
ajax-spinner.css, .load-more__*, --skeleton-base/--skeleton-shine) plus the
unregistered assets/js/waterfall.js.
- Extend the widget, message-centre, user-home and asset-ledger contract
tests to pin the loader inside the container, the class-only visibility
switch, and the absence of the deleted dead code.
Verified: 470 node tests, 136 PHP widget assertions, admin-contract and
widget-system audits all green; rebuilt public assets after the CSS/JS
removals.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -60,6 +60,38 @@ test('old asset implementations and compatibility aliases are absent', () => {
|
||||
assert.deepEqual(violations, [])
|
||||
})
|
||||
|
||||
test('skeleton loading ships one contract and no dead spinner stylesheets', () => {
|
||||
// The skeleton contract is the shared .placeholder block inside a
|
||||
// .post_ajax_loader wrapper. The standalone helpers below were never wired
|
||||
// to any producer and were removed; they must not come back as a second path.
|
||||
for (const removed of [
|
||||
'assets/css/frontend/skeleton.css',
|
||||
'assets/css/frontend/ajax-spinner.css',
|
||||
'assets/js/waterfall.js',
|
||||
]) {
|
||||
assert.equal(fs.existsSync(path.join(root, removed)), false, `${removed} must stay deleted`)
|
||||
}
|
||||
|
||||
const build = fs.readFileSync(path.join(root, 'tools', 'build-public-assets.mjs'), 'utf8')
|
||||
for (const dropped of ['skeleton.css', 'ajax-spinner.css']) {
|
||||
assert.doesNotMatch(build, new RegExp(dropped.replace('.', '\\.')))
|
||||
}
|
||||
|
||||
// Dead rule families with no producer in PHP or JS.
|
||||
const css = sourceFiles(path.join(root, 'assets', 'css'))
|
||||
.filter((f) => !f.includes('build') && !f.endsWith('.min.css'))
|
||||
for (const file of css) {
|
||||
const text = fs.readFileSync(file, 'utf8')
|
||||
assert.doesNotMatch(text, /\.load-more__(?:btn|spinner)/, `${path.relative(root, file)} must not reintroduce .load-more__*`)
|
||||
assert.doesNotMatch(text, /\.aksrt-loading__(?:spinner|overlay|inline|text|dot)/, `${path.relative(root, file)} must not reintroduce .aksrt-loading__*`)
|
||||
assert.doesNotMatch(text, /aksrt-progress-bar/, `${path.relative(root, file)} must not reintroduce .aksrt-progress-bar`)
|
||||
// A second parallel skeleton system (never wired to any producer).
|
||||
assert.doesNotMatch(text, /\.aksrt-skeleton/, `${path.relative(root, file)} must not reintroduce .aksrt-skeleton-*`)
|
||||
assert.doesNotMatch(text, /aksrt-skeleton-shimmer/, `${path.relative(root, file)} must not reintroduce the parallel shimmer keyframes`)
|
||||
assert.doesNotMatch(text, /--skeleton-(?:base|shine)/, `${path.relative(root, file)} must not reintroduce the unused skeleton tokens`)
|
||||
}
|
||||
})
|
||||
|
||||
test('asset tables are InnoDB and operation keys are unique', () => {
|
||||
const schema = fs.readFileSync(path.join(root, 'src', 'Core', 'DBMigratorPart2.php'), 'utf8')
|
||||
for (const table of ['asset_account', 'asset_transaction', 'asset_entry']) {
|
||||
|
||||
@@ -69,6 +69,36 @@ test('message pagination setting switches between cumulative loading and numeric
|
||||
assert.match(styles, /\.messages-pagination__button\.is-current/);
|
||||
});
|
||||
|
||||
test('message centre shows a skeleton during the AJAX load-more cycle', () => {
|
||||
const list = read('inc/modules/message-center.php');
|
||||
const placeholder = read('inc/helpers/message-placeholder.php');
|
||||
const script = read('assets/js/messages.js');
|
||||
const styles = read('assets/css/frontend/messages.css');
|
||||
|
||||
// The skeleton ships inside .messages-list so the loader is anchored to the
|
||||
// end of the list, mirroring the reference post_ajax beforeSend hook.
|
||||
assert.match(list, /aksrt_get_message_placeholder\(4\)/);
|
||||
assert.match(placeholder, /message-item--placeholder/);
|
||||
assert.match(placeholder, /class="post_ajax_loader"/);
|
||||
// The message skeleton reuses the shared .placeholder shimmer contract.
|
||||
assert.match(placeholder, /placeholder t1/);
|
||||
assert.match(placeholder, /placeholder k2/);
|
||||
assert.match(placeholder, /placeholder s1/);
|
||||
|
||||
// Load cycle: show on start, hide on finish, and never remove the node.
|
||||
assert.match(script, /content\.querySelector\('\.messages-list > \.post_ajax_loader'\)/);
|
||||
assert.match(script, /skeleton\.classList\.add\('is-loading'\)/);
|
||||
assert.match(script, /loader\.classList\.remove\('is-loading'\)/);
|
||||
// Appended rows land before the skeleton so it stays flush under the list.
|
||||
assert.match(script, /currentList\.insertBefore\(item, skeleton\)/);
|
||||
|
||||
// Visibility is class-driven; the old button spinner / opacity dim are gone.
|
||||
assert.match(styles, /\.messages-list > \.post_ajax_loader \{/);
|
||||
assert.match(styles, /\.messages-list > \.post_ajax_loader\.is-loading \{/);
|
||||
assert.doesNotMatch(styles, /messages-pagination-spin/);
|
||||
assert.doesNotMatch(styles, /opacity: 0\.55/);
|
||||
});
|
||||
|
||||
test('tabs, pagination, actions, and detail all replace DOM fragments', () => {
|
||||
const center = read('inc/modules/message-center.php');
|
||||
const script = read('assets/js/messages.js');
|
||||
|
||||
@@ -44,6 +44,11 @@ test('the article stream exposes only the new typed renderer contract', () => {
|
||||
assert.doesNotMatch(consumers, /function_exists\(['"]aksrt_render_post_list/);
|
||||
assert.doesNotMatch(consumers, /aksrt_render_post_list\(\s*\$query\s*,/);
|
||||
assert.doesNotMatch(consumers, /content-post-card|aksrt_homepage_render_post_card/);
|
||||
|
||||
// 搜索页的加载态必须是文章同构骨架,而不是遗留的转圈 spinner,
|
||||
// 这样 runtime main.js 的 list 型 loader 形状才与搜索结果一致。
|
||||
assert.match(read('search.php'), /post_ajax_loader search-loader"><\?php echo function_exists\('aksrt_render_placeholder'\) \? aksrt_render_placeholder\('list', 6\)/);
|
||||
assert.doesNotMatch(read('search.php'), /class="loading mr10"/);
|
||||
});
|
||||
|
||||
test('settings use legacy list modes, grouped options, and destructive related keys', () => {
|
||||
@@ -224,6 +229,8 @@ test('related posts, author page and widgets use their dedicated renderers', ()
|
||||
const relatedCard = read('inc/helpers/aksrt-single-components.php');
|
||||
const resourceRelated = read('templates/parts/resource-related.php');
|
||||
const author = read('templates/parts/user-home/panel-posts.php');
|
||||
const authorFavorites = read('templates/parts/user-home/panel-favorites.php');
|
||||
const userHomeCss = read('assets/css/routes/user-home.css');
|
||||
const widgets = read('src/WidgetSystem/PostRenderer.php');
|
||||
|
||||
assert.match(related, /\['img', 'list', 'text'\]/);
|
||||
@@ -249,6 +256,14 @@ test('related posts, author page and widgets use their dedicated renderers', ()
|
||||
assert.match(author, /'wrapper_class'\s*=>\s*'aksrt-user-home__post-list'/);
|
||||
assert.match(author, /aksrt_render_user_home_pagination\(\(int\) \$author_posts->max_num_pages, \(int\) \$posts_page\)/);
|
||||
assert.doesNotMatch(author, /aksrt_render_pagination|aksrt_render_profile_pagination|\$_GET|add_query_arg/);
|
||||
// 面板 AJAX 翻页的骨架:与文章列表同一个 .post_ajax_loader 契约,
|
||||
// 由 author.js 的 .is-loading 切换(不能再靠 opacity 变暗反馈)。
|
||||
assert.match(author, /'append_inner_html' => \$user_home_panel_loader/);
|
||||
assert.match(author, /aksrt_render_placeholder\('list', max\(4, \(int\) \$per_page\)\)/);
|
||||
assert.match(authorFavorites, /'append_inner_html' => \$user_home_panel_loader/);
|
||||
assert.match(userHomeCss, /\.aksrt-user-home \.dashboard-panel \.post_ajax_loader \{/);
|
||||
assert.match(userHomeCss, /\.aksrt-user-home \.dashboard-panel\.is-loading \.post_ajax_loader \{/);
|
||||
assert.doesNotMatch(userHomeCss, /\.dashboard-panel\.is-loading \{[\s\S]{0,80}opacity: \.6/);
|
||||
assert.match(widgets, /aksrt_render_mini_list/);
|
||||
assert.match(widgets, /swiper-container swiper-scroll/);
|
||||
});
|
||||
@@ -454,7 +469,9 @@ test('profile routes load versioned leaf styles and keep dialogs hidden initiall
|
||||
assert.doesNotMatch(panelFavorites, /'type'\s*=>\s*'list'/);
|
||||
assert.match(panelFavorites, /'context'\s*=>\s*'author'/);
|
||||
assert.match(panelFavorites, /aksrt_render_user_home_pagination\(\(int\) \$favorites_query->max_num_pages, \(int\) \$favorites_page\)/);
|
||||
assert.match(panelFavorites, /array_merge\(\$user_home_render_config, \['wrapper_class' => 'aksrt-user-home__post-list'\]\), \$favorites_query\)/);
|
||||
assert.match(panelFavorites, /array_merge\(\$user_home_render_config, \['wrapper_class' => 'aksrt-user-home__post-list', 'append_inner_html' => \$user_home_panel_loader\]\), \$favorites_query\)/);
|
||||
assert.match(panelFavorites, /aksrt_render_placeholder\('list', max\(4, \(int\) \$per_page\)\)/);
|
||||
assert.match(read('templates/parts/user-home/panel-posts.php'), /array_merge\(\$user_home_render_config, \['wrapper_class' => 'aksrt-user-home__post-list', 'append_inner_html' => \$user_home_panel_loader\]\), \$author_posts\)/);
|
||||
assert.doesNotMatch(panelFavorites, /profile-list-item|\$_GET|add_query_arg/);
|
||||
// Only the two-column user center spans the viewport; the single-column public
|
||||
// profile keeps following the admin content max width.
|
||||
|
||||
@@ -25,6 +25,43 @@ test('tab and slider renderers retain reference DOM contracts', () => {
|
||||
for (const token of ['relative zib-slider', 'new-swiper slide-widget', 'swiper-wrapper', 'swiper-slide', 'slide-layer', 'data-swiper-parallax', 'swiper-button-prev', 'swiper-pagination', 'widget-slider-graphic', 'slider-col', 'cover-col', 'widget-graphic-cover']) assert.match(slider, new RegExp(token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')));
|
||||
});
|
||||
|
||||
test('widget skeleton lives inside the AJAX container so the REST client can find it', () => {
|
||||
const content = read('src/WidgetSystem/Renderers/ContentRenderer.php');
|
||||
|
||||
// The loader must be emitted inside .widget-ajaxpager: frontend.js resolves
|
||||
// it with container.querySelector('.post_ajax_loader'). A sibling node would
|
||||
// never match and no skeleton could appear on 加载更多.
|
||||
assert.match(content, /\. \$loader \. '<\/div>'/);
|
||||
assert.match(content, /aria-busy="false"><div class="post_ajax_loader" role="status"/);
|
||||
|
||||
// No pane may append the loader as a sibling of the pager.
|
||||
assert.doesNotMatch(content, /\$body \.= '<div class="post_ajax_loader">'/);
|
||||
});
|
||||
|
||||
test('widget REST client keeps the skeleton across the load-more cycle', () => {
|
||||
const frontend = read('assets/widgets/frontend.js');
|
||||
|
||||
// Reference-parity loader switch: a class, never an inline display that
|
||||
// would outrank the stylesheet and freeze the skeleton shut.
|
||||
assert.match(frontend, /var loader = loaderOf\(container\) \|\| container\.appendChild\(fallbackLoader\(\)\);/);
|
||||
assert.match(frontend, /loader\.classList\.add\('is-loading'\)/);
|
||||
assert.doesNotMatch(frontend, /loader\.style\.display/);
|
||||
|
||||
// The skeleton is anchored to the end of the list on every request, exactly
|
||||
// like the reference post_ajax beforeSend hook.
|
||||
assert.match(frontend, /function anchorLoader\(container\) \{/);
|
||||
assert.match(frontend, /if \(!loader\) return null;/);
|
||||
assert.match(frontend, /pag\.parentNode\.insertBefore\(loader, pag\)/);
|
||||
|
||||
// Appended cards must land before the skeleton, so the skeleton always sits
|
||||
// flush under the last card.
|
||||
assert.match(frontend, /var anchor = loaderOf\(container\) \|\| container\.querySelector\(':scope > \.ajax-pag'\);/);
|
||||
|
||||
// A replace must preserve the loader node (the reference success only hides it).
|
||||
assert.match(frontend, /if \(child !== loader && !child\.classList\.contains\('ajax-pag'\)\) child\.remove\(\);/);
|
||||
assert.match(frontend, /return fetch\(itemsUrl\(/);
|
||||
});
|
||||
|
||||
test('reference slider CSS includes responsive height and combo selectors', () => {
|
||||
const css = read('assets/widgets/frontend.css');
|
||||
const mainCss = read('assets/css/main.css');
|
||||
|
||||
Reference in New Issue
Block a user