Fixes a startup load-order bug where constraints.js could execute before interface.js and throw#5833
Merged
walterbender merged 5 commits intosugarlabs:masterfrom Mar 15, 2026
Merged
Conversation
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
2 similar comments
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
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 |
Contributor
|
@Rohit-rk07 duplicate of PR #5674.please close this to avoid duplicate work |
9dc2dca to
ed8b0cc
Compare
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
ed8b0cc to
9dc2dca
Compare
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.
9dc2dca to
690e039
Compare
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Category
PR Category
System.Object[]
Summary
Fixes a startup load-order bug where
constraints.jscould execute beforeinterface.jsand throw:Uncaught ReferenceError: JSInterface is not definedCloses #5671.
Root Cause
js/js-export/constraints.jswrote directly toJSInterface._methodArgConstraintsat top level, which fails ifJSInterfacehas not been defined yet.Changes
js/js-export/constraints.jsMoved constraints into a local object:
__MB_methodArgConstraintsAdded safe attachment logic:
attach immediately if
JSInterfaceexistsotherwise store in
globalThis.__MB_pending_methodArgConstraintsUpdated CommonJS export to export the constraints object directly
js/js-export/interface.jsOn class load, checks for
globalThis.__MB_pending_methodArgConstraintsAttaches pending constraints to
JSInterface._methodArgConstraintsClears 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=falseResult:
Extra sanity check:
Required
constraints.jsbeforeinterface.jsin NodeConfirmed no
ReferenceErrorand constraints attached successfully