Skip to content

Fix LDK reader crash under ES2023 target of @labkey/api#303

Merged
labkey-bpatel merged 1 commit into
developfrom
fb_ehr_es2023_fix
Jul 13, 2026
Merged

Fix LDK reader crash under ES2023 target of @labkey/api#303
labkey-bpatel merged 1 commit into
developfrom
fb_ehr_es2023_fix

Conversation

@labkey-bpatel

@labkey-bpatel labkey-bpatel commented Jul 13, 2026

Copy link
Copy Markdown

Rationale

Under the pre-ES2023 target of @labkey/api, TypeScript compiled FieldKey.fromParts to a plain function property. Regular functions in JS are constructable, and when you call one with new and the function explicitly returns an object, new just hands back that returned object — so new LABKEY.FieldKey.fromParts(x) and LABKEY.FieldKey.fromParts(x) produced the same value, and the misused new was redundant but harmless. Under ES2023, FieldKey emits as a native ES6 class and fromParts becomes a real class static method. Static methods on native ES6 classes can be called normally but are not constructors — invoking one with new throws TypeError: … is not a constructor.

The bad call sits in the readRecords override in LabKeyStore.js. When new throws, the reader aborts before finishing its setup, leaving downstream Ext stores unable to identify their records on submit. That's what broke the JHU_EHR and NIRC_EHR data-entry tests (https://teamcity.labkey.org/buildConfiguration/LabkeyTrunk_EhrPostgres?branch=%3Cdefault%3E&buildTypeTab=overview#all-projects). However, this isn't a test-only fix, any Ext4 store whose reader chain resolves to LDK.data.proxy.ExtendedJsonReader - the default for LDK.data.LabKeyStore and everything extending it (EHR.data.DataEntryServerStore in particular) - hangs or fails on submit for real users whenever the query metadata carries a field without a name

Related Pull Requests

Changes

  • LDK/resources/web/LDK/data/LabKeyStore.js: drop the redundant new from the call to LABKEY.FieldKey.fromParts(field.fieldKey). fromParts is a factory that already constructs and returns a FieldKey; no behavior change other than restoring compatibility with ES2023-compiled @labkey/api.

Under the pre-@labkey/api-1.52.0 ES5 target, `FieldKey.fromParts` was compiled to a plain function property, which is [[Construct]]-able, so `new LABKEY.FieldKey.fromParts(...)` worked by convention. Once @labkey/api targets ES2023 (labkey-api-js#219) the class is emitted as a native ES6 class whose static methods are not constructors, so the `new` call throws `TypeError: not a constructor`. The exception unwinds `Ext4.each` before the reader's `readRecords` calls `callParent`, so `idProperty` is never set on the reader and every subsequent update fails the "Record passed as update which lacks keyfield" assertion in EHR data-entry stores.
@labkey-bpatel

Copy link
Copy Markdown
Author

@bbimber Thank you!

@labkey-bpatel labkey-bpatel merged commit 6404d0f into develop Jul 13, 2026
9 of 10 checks passed
@labkey-bpatel labkey-bpatel deleted the fb_ehr_es2023_fix branch July 13, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants