Environment
- MarkBind v7.2.1
- GitHub Pages project site
- Non-empty
baseUrl (for example, /IT2900)
Description
Pagefind search fails on sites deployed under a subpath. The generated page defines the base URL as a top-level lexical binding:
<script>
const baseUrl = '/IT2900'
</script>
However, packages/core-web/asset/js/pagefind-lazyloader.js reads it as a property of window:
const baseUrl = window.baseUrl || '';
const module = await import(`${baseUrl}/markbind/pagefind/pagefind.js`);
A top-level const does not create a window property. As a result, window.baseUrl is undefined, the fallback empty string is used, and Pagefind attempts to import from the domain root when the Pagefind <search /> UI is opened.
For a site with baseUrl: "/IT2900":
- Actual request:
/markbind/pagefind/pagefind.js (404)
- Expected request:
/IT2900/markbind/pagefind/pagefind.js (200)
The Pagefind assets are generated correctly at the expected subpath; only the lazy-loader import URL is incorrect.
Steps to reproduce
- Configure a MarkBind site with a non-empty base URL and Pagefind enabled:
{
"baseUrl": "/example",
"pagefind": {
"enablePagefind": true
}
}
- Add the Pagefind component
<search /> to a page or layout. Note that <searchbar> is the separate legacy heading-search component and does not exercise this code path.
- Run
markbind build.
- Serve
_site so that it is available under /example.
- Open the Pagefind search UI.
- Observe that the browser requests
/markbind/pagefind/pagefind.js instead of /example/markbind/pagefind/pagefind.js.
Suggested fixes
Either expose the generated value explicitly:
<script>
window.baseUrl = '{{ baseUrl }}'
</script>
or have the lazy loader consume a value that is passed without relying on a window property.
Additional evidence
The issue is present in both the v7.2.1 generated output and the current master versions of packages/core/src/Page/page.njk and packages/core-web/asset/js/pagefind-lazyloader.js.
Environment
baseUrl(for example,/IT2900)Description
Pagefind search fails on sites deployed under a subpath. The generated page defines the base URL as a top-level lexical binding:
However,
packages/core-web/asset/js/pagefind-lazyloader.jsreads it as a property ofwindow:A top-level
constdoes not create awindowproperty. As a result,window.baseUrlisundefined, the fallback empty string is used, and Pagefind attempts to import from the domain root when the Pagefind<search />UI is opened.For a site with
baseUrl: "/IT2900":/markbind/pagefind/pagefind.js(404)/IT2900/markbind/pagefind/pagefind.js(200)The Pagefind assets are generated correctly at the expected subpath; only the lazy-loader import URL is incorrect.
Steps to reproduce
{ "baseUrl": "/example", "pagefind": { "enablePagefind": true } }<search />to a page or layout. Note that<searchbar>is the separate legacy heading-search component and does not exercise this code path.markbind build._siteso that it is available under/example./markbind/pagefind/pagefind.jsinstead of/example/markbind/pagefind/pagefind.js.Suggested fixes
Either expose the generated value explicitly:
or have the lazy loader consume a value that is passed without relying on a
windowproperty.Additional evidence
The issue is present in both the v7.2.1 generated output and the current
masterversions ofpackages/core/src/Page/page.njkandpackages/core-web/asset/js/pagefind-lazyloader.js.