setNavigation() is invoked before all pages are loaded
See original GitHub issueWhen loading several pages, I have noticed that my navigation bar (.cms_nav
) was lacking some links. My guess, the reason for that is that the end of content load is compared with page count using an ID-like-variable, not an actual counter.
Short explanation
Pages are loaded asynchronously and the “counter” (value that is accessed by Ajax success
) is passed by iterating the filenames in getFiles()
. The navigation bar is loaded when the counter is equal to the count of the pages. There can be a situation where a last page is loaded first and the navigation bar is created prematurely.
Long explanation
Load flow goes like this:
CMS.getFiles(type)
is invoked at line 428 wheretype === 'page'
- Inside
getFiles(type)
Ajax call is performed to get files in the directory - On
success
.md filenames are extracted - For each file
CMS.getContent()
is invoked at line 350 with iterated “counter” - Each file is fetched in
CMS.getContent()
using an Ajax call - On
success
‘parseContent()’ is invoked passing a “counter” - If
counter === numFiles
(i.e., if the “counter” of the file is the same as the count of files), theCMS.contentLoaded()
is invoked (at line 245) and (if posts are loaded already), navigation bar is loaded
This means, that if the last page (alphanumerically on the getFiles()
Ajax load) is loaded first, then counter === numFiles
is true
, and the navigation is not loaded properly.
Replication
Create pages A.mb, B.mb and C.mb. Make A substantially larger so it would load last. Navigation bar should only contain C (and maybe B) and not A. Make sure to clean the cache.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
Hey guys! I’m back and trying to get this train rolling again. Over the next few weeks I’m going to try and get caught up with these issues and PRs. Thanks for all the suggestions and support!
@codeGlaze, yeah, was wondering if that will happen. Maybe with #71 things will start moving forward.