Skip to content

fix(enketo): silence false-positive 'no context element found' errors#10962

Open
sh1vam31 wants to merge 2 commits intomedic:masterfrom
sh1vam31:9684-fix-enketo-repeat-relevant-error
Open

fix(enketo): silence false-positive 'no context element found' errors#10962
sh1vam31 wants to merge 2 commits intomedic:masterfrom
sh1vam31:9684-fix-enketo-repeat-relevant-error

Conversation

@sh1vam31
Copy link
Copy Markdown
Contributor

Description

Fixes #9684

This PR implements a patch for enketo-core to resolve a persistent "no context element found" console error. The error occurs when adding or removing entries in a repeat group while another repeat group in the same form is empty and contains fields with relevant expressions.

Solution

When a repeat group's instances change, Enketo triggers a global update that re-evaluates expressions for all fields. If a different repeat group is empty, Enketo's evaluate function fails to find a context node for its fields, resulting in a false-positive console error.

The patch modifies FormModel.prototype.evaluate to:

  • Detect when a context node is missing but a selector path is provided.
  • Return a type-appropriate default value (false for booleans, [] for node sets, NaN for numbers) instead of logging an error.
  • Silence the console.error for these specific, expected cases.

Patch Verification:

  • Verified that the patch applies cleanly using patch-package.
  • Verified that the logic correctly handles all XPath result types (boolean, string, number, node, nodes).

Code review checklist

  • UI/UX backwards compatible: Test it works for the new design (enabled by default). And test it works in the old design, enable can_view_old_navigation permission to see the old design. Test it has appropriate design for RTL languages.
  • Readable: Concise, well named, follows the style guide
  • Documented: Configuration and user documentation on cht-docs
  • Tested: Unit and/or e2e where appropriate
  • Internationalised: All user facing text
  • Backwards compatible: Works with existing data and configuration or includes a migration. Any breaking changes documented in the release notes.
  • AI disclosure: Please disclose use of AI per the guidelines.

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

- Fix race condition in message-duplicates integration test
- Add github-token to k3d setup to resolve CI rate limiting
@sh1vam31
Copy link
Copy Markdown
Contributor Author

Hi @jkuester,

This PR resolves #9684 by patching enketo-core to handle missing context nodes gracefully. This silences the false-positive "no context element found" console errors that were occurring during repeat group updates.

I have also included some minor CI and test stability fixes to ensure all checks pass.

Ready for review!

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.

relevant expression inside repeat with no entries causes error when adding new entries to a different repeat

1 participant