mirror of
https://codeberg.org/valpackett/tiddlypwa.git
synced 2025-12-06 02:30:48 -08:00
Plugin: eager-load tiddlers with custom fields, fixes #23
For the Section Editor case, this is actually just a workaround, the real issue is https://github.com/Jermolene/TiddlyWiki5/issues/7686 But this does sound like a heuristic to keep for whatever-else-can-plugins-do.
This commit is contained in:
parent
e8a468b79f
commit
b90e64e05c
1 changed files with 18 additions and 6 deletions
|
|
@ -105,6 +105,23 @@ Formatted with `deno fmt`.
|
||||||
return url === `${location.origin}${location.pathname}${location.search}`;
|
return url === `${location.origin}${location.pathname}${location.search}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const knownFields = new Set(['created', 'creator', 'modified', 'modifier', 'tags', 'text', 'title', 'type', 'uri']);
|
||||||
|
|
||||||
|
// Certain tiddlers must NEVER use _is_skinny lazy-loading
|
||||||
|
function mustEagerLoad(tid) {
|
||||||
|
// e.g. $:/DefaultTiddlers
|
||||||
|
if (tid.title.startsWith('$:')) return true;
|
||||||
|
// e.g. $:/tags/Macro, $:/tags/ManifestIcon
|
||||||
|
for (const t of $tw.Tiddler.fieldModules.tags.parse(tid.tags) || []) {
|
||||||
|
if (typeof t === 'string' && t.startsWith('$:')) return true;
|
||||||
|
}
|
||||||
|
// e.g. se-type from the Section Editor plugin https://codeberg.org/valpackett/tiddlypwa/issues/23
|
||||||
|
// (Actually that case is about core not firing lazyLoad when a custom viewtemplate is used,
|
||||||
|
// but we can imagine other kinds of custom-field-having tiddlers needing content always loaded)
|
||||||
|
for (const k of Object.keys(tid)) if (!knownFields.has(k)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
class FetchError extends Error {
|
class FetchError extends Error {
|
||||||
constructor(cause) {
|
constructor(cause) {
|
||||||
super('fetch failed');
|
super('fetch failed');
|
||||||
|
|
@ -434,12 +451,7 @@ Formatted with `deno fmt`.
|
||||||
// not isReady yet, can safely addTiddler
|
// not isReady yet, can safely addTiddler
|
||||||
const tid = await this.parseEncryptedTiddler({ thash, ct, iv });
|
const tid = await this.parseEncryptedTiddler({ thash, ct, iv });
|
||||||
if (sbiv && sbct) {
|
if (sbiv && sbct) {
|
||||||
// These we need to eager-load no matter what, e.g. we could have a huge DefaultTiddlers end up as separate body
|
if (mustEagerLoad(tid)) {
|
||||||
// Tags are also checked for $: due to $:/tags/Macro, $:/tags/ManifestIcon, etc.
|
|
||||||
if (
|
|
||||||
tid.title.startsWith('$:') ||
|
|
||||||
$tw.Tiddler.fieldModules.tags.parse(tid.tags)?.find((x) => typeof x === 'string' && x.startsWith('$:'))
|
|
||||||
) {
|
|
||||||
tid.text = await decodeData(
|
tid.text = await decodeData(
|
||||||
await crypto.subtle.decrypt({ name: 'AES-GCM', iv: sbiv }, this.enckey(thash), sbct),
|
await crypto.subtle.decrypt({ name: 'AES-GCM', iv: sbiv }, this.enckey(thash), sbct),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue