-
-
Notifications
You must be signed in to change notification settings - Fork 6
Throw exception when layout missing required tags for asset injection #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: grantcopley <1197835+grantcopley@users.noreply.github.com>
Co-authored-by: grantcopley <1197835+grantcopley@users.noreply.github.com>
interceptors/CBWIRE.cfc
Outdated
| function postLayoutRender() { | ||
| if ( shouldInject( arguments.event ) && !request.keyExists( "_cbwire_injected_assets" ) ) { | ||
| // Check if the layout has required tags for asset injection | ||
| if ( !findNoCase( "</head>", arguments.data.renderedLayout ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot I don't like how we are using findNoCase() here on arguments.data.renderedLayout, because that potentially could be a huge text string of rendered dynamic content. Instead, if we use the private collection (arguments.event.getPrivateCollection()), we should get a struct back with 'currentLayout', which usually is 'Main', which could then be used to just fileRead( 'layouts/Main.bxm' ) or .cfm. This allows us to then check that file for and tags much faster as we don't care for the fully rendered content to perform the check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! I've optimized the implementation to read the layout file directly instead of checking the rendered content.
Changes in commit e4a2347:
- Added
getLayoutContent()helper method that reads the actual layout file from disk - Gets layout name from
event.getPrivateValue("currentLayout") - Supports both
.cfmand.bxmfile extensions - Validates against the smaller layout file content instead of the potentially large rendered HTML
This approach is more efficient and avoids scanning large dynamically-rendered content.
…ered content Co-authored-by: grantcopley <1197835+grantcopley@users.noreply.github.com>
lucee@6 Test Results296 tests +3 272 ✅ +1 4s ⏱️ ±0s For more details on these failures, see this check. Results for commit 9713840. ± Comparison against base commit 877042a. ♻️ This comment has been updated with latest results. |
adobe@2023 Test Results296 tests +3 272 ✅ +1 7s ⏱️ -1s For more details on these failures, see this check. Results for commit 9713840. ± Comparison against base commit 877042a. ♻️ This comment has been updated with latest results. |
lucee@5 Test Results296 tests +3 272 ✅ +1 5s ⏱️ ±0s For more details on these failures, see this check. Results for commit 9713840. ± Comparison against base commit 877042a. ♻️ This comment has been updated with latest results. |
boxlang-cfml@1 Test Results296 tests +3 276 ✅ +1 10s ⏱️ ±0s For more details on these failures, see this check. Results for commit 9713840. ± Comparison against base commit 877042a. ♻️ This comment has been updated with latest results. |
adobe@2025 Test Results296 tests +3 272 ✅ +1 6s ⏱️ ±0s For more details on these failures, see this check. Results for commit 9713840. ± Comparison against base commit 877042a. ♻️ This comment has been updated with latest results. |
|
Closing as this ended up being a performance killer. |
</head>or</body>tagspostLayoutRender()ininterceptors/CBWIRE.cfcto throw exception when tags are missingSummary
Successfully implemented exception throwing when layouts are missing required HTML tags for CBWIRE asset injection, with performance optimization based on code review feedback.
Key Implementation Details
postLayoutRender()to validate presence of</head>and</body>tags before attempting asset injectiongetLayoutContent()helper that reads layout file directly instead of checking rendered HTMLCBWIREExceptionwith actionable guidance when tags are missingPerformance Improvement (Commit e4a2347)
Instead of using
findNoCase()on potentially largearguments.data.renderedLayout:event.getPrivateValue("currentLayout").cfmand.bxmextensionsOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.