Skip to content

Fixes a startup load-order bug where constraints.js could execute before interface.js and throw#5833

Merged
walterbender merged 5 commits intosugarlabs:masterfrom
Rohit-rk07:fix-5671-clean
Mar 15, 2026
Merged

Fixes a startup load-order bug where constraints.js could execute before interface.js and throw#5833
walterbender merged 5 commits intosugarlabs:masterfrom
Rohit-rk07:fix-5671-clean

Conversation

@Rohit-rk07
Copy link
Contributor

@Rohit-rk07 Rohit-rk07 commented Feb 20, 2026

PR Category

  • Bug Fix

PR Category

System.Object[]

Summary

Fixes a startup load-order bug where constraints.js could execute before interface.js and throw:

Uncaught ReferenceError: JSInterface is not defined

Closes #5671.

Root Cause

js/js-export/constraints.js wrote directly to JSInterface._methodArgConstraints at top level, which fails if JSInterface has not been defined yet.

Changes

  • js/js-export/constraints.js

    • Moved constraints into a local object: __MB_methodArgConstraints

    • Added safe attachment logic:

      • attach immediately if JSInterface exists

      • otherwise store in globalThis.__MB_pending_methodArgConstraints

    • Updated CommonJS export to export the constraints object directly

  • js/js-export/interface.js

    • On class load, checks for globalThis.__MB_pending_methodArgConstraints

    • Attaches pending constraints to JSInterface._methodArgConstraints

    • Clears the temporary global after attachment

Why this is safe

  • Preserves existing behavior when scripts load in normal order

  • Adds compatibility for reversed load order

  • Keeps Node/Jest usage intact

Verification

  • Ran:

    • npm test -- --runTestsByPath js/js-export/__tests__/constraints.test.js js/js-export/__tests__/interface.test.js --coverage=false
  • Result:

    • 2 suites passed, 62 tests passed
  • Extra sanity check:

    • Required constraints.js before interface.js in Node

    • Confirmed no ReferenceError and constraints attached successfully

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

2 similar comments
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@Rohit-rk07
Copy link
Contributor Author

Hi @walterbender, @omsuneri 👋

This PR fixes the startup load-order bug where constraints.js could execute before interface.js and throw. Please review

@vanshika2720
Copy link
Contributor

@Rohit-rk07 duplicate of PR #5674.please close this to avoid duplicate work

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

…d order

Avoid direct top-level access to JSInterface in constraints.js so it can load safely before interface.js.

Store constraints in a local object, attach immediately if JSInterface exists, otherwise defer via a temporary global and apply in interface.js.

Fixes sugarlabs#5671.
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@github-actions github-actions bot added the bug fix Fixes a bug or incorrect behavior label Mar 12, 2026
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@walterbender walterbender merged commit 17138b8 into sugarlabs:master Mar 15, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix Fixes a bug or incorrect behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Uncaught ReferenceError: JSInterface is not defined in constraints.js

3 participants