-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Open
Labels
aws-cdk-libRelated to the aws-cdk-lib packageRelated to the aws-cdk-lib packagebugThis issue is a bug.This issue is a bug.needs-triageThis issue or PR still needs to be triaged.This issue or PR still needs to be triaged.
Description
Describe the bug
App.of() falls through to Stage.of(), which finds the first Stage in scopes (excluding itself), causing:
- Returns
Stageinstead ofAppwhen both exist in hierarchy - Returns
undefinedwhen called on App itself
Fix: Direct root check using construct.node.root and App.isApp() validation.
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Library Version
No response
Expected Behavior
App.of() should return the root App.
Current Behavior
App.of() can sometimes return a Stage (which is not an App) or undefined.
Reproduction Steps
const app = new App();
const stage = new Stage(app, 'TestStage');
const stack = new Stack(stage, 'TestStack');
App.of(stack); // Returns 'stage' instead of 'app' ❌
const app2 = new App();
App.of(app2); // Returns undefined instead of 'app2' ❌Possible Solution
Additional Information/Context
No response
AWS CDK Library version (aws-cdk-lib)
ALL
AWS CDK CLI version
N/A
Node.js Version
N/A
OS
N/A
Language
N/A
Language Version
No response
Other information
No response
Metadata
Metadata
Assignees
Labels
aws-cdk-libRelated to the aws-cdk-lib packageRelated to the aws-cdk-lib packagebugThis issue is a bug.This issue is a bug.needs-triageThis issue or PR still needs to be triaged.This issue or PR still needs to be triaged.