CloudCannon / pagefind

Static low-bandwidth search at scale
https://pagefind.app
MIT License
3.22k stars 97 forks source link

Improve Pagefind compatibility when future JS/WASM API changes are released #597

Open c-w opened 2 months ago

c-w commented 2 months ago

I started seeing the following error in Sentry since upgrading to pagefind@1.1.0:

RuntimeError: Unreachable code should not be executed (evaluating 'malloc(arg.length*1)')
  at passArray8ToWasm0 (/_pagefind/pagefind.js:1:502)
  at None (/_pagefind/pagefind.js:1:665)
  at None (/_pagefind/pagefind.js:1:18306)

Looks like the error is unrecoverable and all pagefind API calls afterwards fail.

Perhaps it's related to this console warning?

Pagefind JS version doesn't match the version in your search index.
Pagefind JS: 1.0.4. Pagefind index: 1.1.0
If you upgraded Pagefind recently, you likely have a cached pagefind.js file.
If you encounter any search errors, try clearing your cache.
c-w commented 2 months ago

Confirmed that this seems due to caching /_pagefind/pagefind.js across version updates. The console warning is useful but not a panacea (as for example it's not trivial to stumble across it during development). Perhaps it would be useful to add a cache busting param such as ?v={your_pagefind_version} to the docs where import("/_pagefind/pagefind.js") is referenced?

bglw commented 2 months ago

Yeah that might be a good option, though a little unfortunate to push as a requirement to the end user.

Now that Pagefind has pretty wide uptake, it might be time to enforce a goal that future JS/WASM updates are backwards compatible with each other, to stem some of the errors.

Another path might be to make Pagefind self-patch this issue. Where it currently logs the warning error, I wonder if it could instead reimport itself with a query parameter to cache bust, and defer its methods to the imported file.

Something to ruminate on!