Skip to content

fix(script): pending TextDocument baseline edits leave baseline getters stale #549

Closed

Description

@coygeek

Summary

Reading superscript or subscript from a Source Text.value document immediately after assigning one of those flags returns the previous baseline state in EffectCraft. A script that uses that read to choose its text can write the wrong text even though setValue applies the requested baseline. The example below writes "normal" rather than "super" and retains that result after the project reopens. Applying one baseline edit and reading a fresh Source Text.value provides the correct flags for the tested inputs.

Runtime or environment

The independently executed reproduction used the source-built headless effectcraft-cli 0.7.0 at revision 813c7c4. Its binary SHA-256 was 7139cd25e007c57e9de3fb22c60ef6efd0586be09a13237214c0a36c2242d4fe. The fixture starts empty, creates a 128 by 128 composition and uses uniform unkeyed text with default scripting preferences. It requires no desktop session, external media or model download. Put a CLI built from this source on PATH and use a disposable working directory.

Steps to reproduce

  1. Save this complete script as pending-document.jsx. Each setValue applies at most one changed baseline flag. The first layer reads its pending document before application; the other layers check fresh reads and the explicit baseline command.
var comp = app.project.items.addComp("Baseline check", 128, 128, 1, 1, 24);
var layer = comp.layers.addText("AB");
layer.name = "Script text";
var source = layer.text.sourceText;
function state(document) { return [document.text, document.superscript, document.subscript]; }
var results = {};
var document = source.value;
document.superscript = true;
results.scriptPending = state(document);
document.text = document.superscript ? "super" : "normal";
source.setValue(document);
results.scriptApplied = state(source.value);
document = source.value;
document.subscript = true;
results.scriptSwitchPending = state(document);
source.setValue(document);
results.scriptSwitchApplied = state(source.value);
document = source.value;
document.subscript = false;
results.scriptOffPending = state(document);
source.setValue(document);
results.scriptOffApplied = state(source.value);
document = source.value;
document.superscript = true;
source.setValue(document);
results.scriptSaved = state(source.value);
var fresh = comp.layers.addText("AB");
fresh.name = "Fresh read control";
var freshSource = fresh.text.sourceText;
document = freshSource.value;
document.superscript = true;
freshSource.setValue(document);
document = freshSource.value;
results.workaroundSuper = state(document);
document.text = document.superscript ? "super" : "normal";
freshSource.setValue(document);
results.workaroundBranch = state(freshSource.value);
document = freshSource.value;
document.subscript = true;
freshSource.setValue(document);
results.workaroundSwitch = state(freshSource.value);
document = freshSource.value;
document.subscript = false;
freshSource.setValue(document);
results.workaroundOff = state(freshSource.value);
document = freshSource.value;
document.superscript = true;
freshSource.setValue(document);
var commandLayer = comp.layers.addText("AB");
commandLayer.name = "Command control";
comp.openInViewer();
app.run("layer.setText", {layer:"Command control", baseline:"superscript"});
results.scriptCommandControl = state(commandLayer.text.sourceText.value);
JSON.stringify(results);
  1. Run the fixture with configuration and its saved project contained in the disposable working directory.
mkdir -p config
export EFFECTCRAFT_CONFIG_DIR="$PWD/config"
effectcraft-cli script pending-document.jsx --empty --save-as pending-document.ecproj --json
  1. Save this readback script as reopen-document.jsx and run it against the saved project.
var comp = app.project.item(1); function state(document) { return [document.text, document.superscript, document.subscript]; } JSON.stringify({scriptReloaded:state(comp.layer("Script text").text.sourceText.value), workaroundReloaded:state(comp.layer("Fresh read control").text.sourceText.value), commandReloaded:state(comp.layer("Command control").text.sourceText.value)});
effectcraft-cli script reopen-document.jsx pending-document.ecproj --json

Both script invocations were independently executed and exited 0 with ok:true, error:null and empty stderr. The CLI returns the observations as a JSON string in its result field. The reproduction is complete for this scripting entry point.

Expected behavior

EffectCraft's writable pending document should expose the baseline represented by its single edit. Enabling superscript on normal text should immediately read [true,false]; switching a superscript document to subscript should read [false,true]; clearing the enabled subscript flag should read [false,false]. Applying each edit and reading a fresh value should report the same flags.

The initial pending read should therefore be ["AB",true,false] and select "super". The applied, switched, cleared and finally saved script states should keep that chosen text. Reopening the script layer should return ["super",true,false]. The fresh-read workaround and explicit engine baseline control should retain their passing results.

This expectation applies to EffectCraft's implemented setters and pending attribute model. The external After Effects scripting reference describes these two TextDocument booleans as read-only. Their writable behavior in EffectCraft is the contract tested here.

Actual behavior

The first invocation returned this decoded result:

{
  "scriptPending": ["AB", false, false],
  "scriptApplied": ["normal", true, false],
  "scriptSwitchPending": ["normal", true, false],
  "scriptSwitchApplied": ["normal", false, true],
  "scriptOffPending": ["normal", false, true],
  "scriptOffApplied": ["normal", false, false],
  "scriptSaved": ["normal", true, false],
  "workaroundSuper": ["AB", true, false],
  "workaroundBranch": ["super", true, false],
  "workaroundSwitch": ["super", false, true],
  "workaroundOff": ["super", false, false],
  "scriptCommandControl": ["AB", true, false]
}

All three pending reads report the old state. Each fresh read after setValue reports the requested single edit, so the stale initial read selects "normal" while the applied document has superscript enabled. The final superscript assignment preserves the text that the branch already chose.

The reopen invocation returned:

{
  "scriptReloaded": ["normal", true, false],
  "workaroundReloaded": ["super", true, false],
  "commandReloaded": ["AB", true, false]
}

These observations establish getter values, the resulting text choice and project persistence. No frames were rendered, so they do not establish pixel correctness or reference-application rendering parity.

Evidence

  • Expected source: EffectCraft's writable document and changed-attribute precedence in crates/script/src/prelude.js:408-435, the implemented getter/setter pairs at crates/script/src/prelude.js:482-485, and the mutually exclusive baseline states accepted at crates/keyframe/src/text_doc.rs:1016-1023. The independently executed fresh-value and explicit baseline controls demonstrate the expected flags for the fixture's edits.
  • Failure source: The executed scripts and decoded results above show pending reads disagreeing with the single edit that setValue applies, selecting the wrong text and retaining it after reopen. The scripting getters read the baseline key while their setters record separate boolean keys at crates/script/src/prelude.js:482-485.
  • Evidence provenance: observed
  • Local verification: reproduced
  • Reproduction completeness: complete

The supported CLI route dispatches to script.run at apps/effectcraft-cli/src/main.rs:366-375. Source Text.setValue converts a document through crates/script/src/prelude.js:742-746,792-796; its changed attributes are applied by crates/script/src/model.rs:528-550. A fresh read includes the first character's applied style through crates/script/src/model.rs:448-457 and crates/keyframe/src/text_doc.rs:1152. The fixture has no keyframes or hidden property, so setValue's guards permit the call.

The external read-only distinction is documented at https://ae-scripting.docsforadobe.dev/text/textdocument/. The report relies on the implemented EffectCraft model and the executed application controls for the pending-read expectation.

Restoration check

Rerun the fixture and require scriptPending to report ["AB",true,false] before application. The branch must choose "super". scriptApplied must then be ["super",true,false], scriptSwitchPending and scriptSwitchApplied must both be ["super",false,true], and scriptOffPending and scriptOffApplied must both be ["super",false,false]. The final single superscript application and reopened script layer must both be ["super",true,false].

Keep the fresh-read control's enable, switch and clear values unchanged, including its "super" branch result and reopened text. Keep the explicit engine baseline control and its reopened ["AB",true,false] result. These checks restore pending/applied agreement on the same document contract and preserve mutually exclusive flags without specifying a repair design.

Triage assessment

  • Impact level: P2
  • Assessment status: supported
  • Impact basis: The executed pending reads produce wrong programmatic values for bounded baseline edits, change a script's selected text and preserve that incorrect text after saving and reopening. The passing application controls and available workaround limit the demonstrated impact; no severe harm or general failure of composition authoring was established.
  • Workaround status: available
  • Workaround basis: For the tested unkeyed uniform text, apply one baseline edit with Source Text.setValue, obtain a fresh Source Text.value and then inspect its flags. The fixture verified superscript [true,false], the "super" branch, switching to subscript [false,true], clearing [false,false] and reopened ["super",true,false]. This requires committing the baseline change before the read rather than inspecting only the pending object. Setting the explicit layer.setText baseline attribute and obtaining a fresh value also verified superscript [true,false] through the command control.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions