TJSApplication Character Sheet odd behavior with unlinked tokens

Has anyone else experienced weird when using a TJSApplication as a character sheet with unlinked tokens? In my system, updating the base actor attempts to render the actor sheet for every token on the scene, regardless of whether that token's sheet was open previously. Every token whose sheet hasn't been rendered yet, will cause a fairly predictable "TypeError: An error occurred while rendering TJSDocSheet 45. this._element is null" - the sheet isn't mounted anywhere, so big surprise there. All other sheets will be made visible simultaneously. I think the SvelteApplication _render is missing the following check from foundry.js:
// Applications which are not currently rendered must be forced
if ( !force && (this._state <= states.NONE) ) return;
// Applications which are not currently rendered must be forced
if ( !force && (this._state <= states.NONE) ) return;
Which requires force=true to summon a closed sheet, as foundry seems like it will frequently render with force=false as a way to update any open sheets. Without this check, any of these "update" renders will cause undesired behavior.
6 Replies
TyphonJS (Michael)
Can you add that gating lines found in Application._render to the top of SvelteApplication._render. IE add:
// Do not render under certain conditions
const states = Application.RENDER_STATES;
if ( [states.CLOSING, states.RENDERING].includes(this._state) ) return;

// Applications which are not currently rendered must be forced
if ( !force && (this._state <= states.NONE) ) return;
// Do not render under certain conditions
const states = Application.RENDER_STATES;
if ( [states.CLOSING, states.RENDERING].includes(this._state) ) return;

// Applications which are not currently rendered must be forced
if ( !force && (this._state <= states.NONE) ) return;
to the top of SvelteApplication._render. There is a chance that this logic was added after SvelteApplication was created and I didn't catch the changes to Application._render. Basically the same conditions that should stop an Application._render process should stop any further logic occurring in SvelteApplication._render. You should be able to just put that bit of code in the node_modules/@typhonjs-fvtt/runtime/_dist/svelte/application/SvelteApplication.js code and rebuild and let me know if things work. There also is a chance that the logic added to core around unlinked tokens re: invoking render without force was recently added which now causes this situation and without the extra gating in SvelteApplication._render the problem arises. I can add this and the TJSGlassPane enhancements to a new release soon.
WHITESPINE
WHITESPINEOP16mo ago
Solution as posted didn't exactly work - gonna iterate on it a bit. Solution worked, thanks. Just had to delete vite-cache. Also discovered another minor issue: When drag re-ordering an item in the items sidebar tab, if that item is configured to use a TJSApplication sheet, it will cause the following error: Uncaught (in promise) TypeError: doc.sheet.submit is not a function Due to the following foundry behavior:
async sortRelative({updateData={}, ...sortOptions}={}) {
const sorting = SortingHelpers.performIntegerSort(this, sortOptions);
const updates = [];
for ( let s of sorting ) {
const doc = s.target;
const update = foundry.utils.mergeObject(updateData, s.update, {inplace: false});
update._id = doc._id;
if ( doc.sheet && doc.sheet.rendered ) await doc.sheet.submit({updateData: update}); // <------------- HERE!
else updates.push(update);
}
if ( updates.length ) await this.constructor.updateDocuments(updates, {parent: this.parent, pack: this.pack});
return this;
}
async sortRelative({updateData={}, ...sortOptions}={}) {
const sorting = SortingHelpers.performIntegerSort(this, sortOptions);
const updates = [];
for ( let s of sorting ) {
const doc = s.target;
const update = foundry.utils.mergeObject(updateData, s.update, {inplace: false});
update._id = doc._id;
if ( doc.sheet && doc.sheet.rendered ) await doc.sheet.submit({updateData: update}); // <------------- HERE!
else updates.push(update);
}
if ( updates.length ) await this.constructor.updateDocuments(updates, {parent: this.parent, pack: this.pack});
return this;
}
I assume this is just because TJSApplication was really just meant to replace Application, not FormApplication, and is thus missing some functionality. An eventual TJSDocumentSheet (or something) would hopefully resolve it - in the meantime I am not super concerned, item sorting isn't exactly mission critical Oh wait - editing things in node_modules doesn't seem to immediately apply the changes in browser - even after restarting dev server / explicitly running npm run build Had to edit vite cache Mostly solved :)
TyphonJS (Michael)
Yeah, the dev server is going to get caught up w/ caching and such. I should have mentioned to make the mod locally and then use production builds to test as the Rollup / production build will pull in any local changes to node_modules. When you say it's mostly solved I take it that the gating solves the non-forced render of sheets that aren't yet visible. The remaining part is that sheets in core Foundry have the update submit method / are FormApplications thus in any system implementation it's necessary to mirror some parts of the Foundry / FormApplication API so that things play nice w/ the core implementation. This is something that can be addressed in adding an exported submit function from the main JS implementation for a sheet.
WHITESPINE
WHITESPINEOP16mo ago
Oh right I forgot I can just define that in my subclass. Yeah that's the only remaining issue
TyphonJS (Michael)
I will try and get that extra gating into an update this week. This should solve the unlinked token / aspects where Foundry is just cycling through all ui.windows / or the token / document sheets and bashing a non-forced render. The problem likely occurred here for non-visible / not currently rendered apps / sheets: https://github.com/typhonjs-fvtt-lib/svelte/blob/main/src/application/SvelteApplication.js#L890 Where the options are being applied to the position system, but the main element is null / since it's not a rendered sheet. The gating in Application._render stops a render, but simply returns and I have to add the same behaviour into SvelteApplication._render to stop further processing. This should be fixed w/ TRL 0.1.2; IE render: false w/ non-rendered apps should not properly function.
WHITESPINE
WHITESPINEOP15mo ago
monkyippee thanks
Want results from more Discord servers?
Add your server