Skip to content

fix for two file wire from within a module#262

Open
mrigsby wants to merge 4 commits intocoldbox-modules:developmentfrom
mrigsby:module-view-path-fix
Open

fix for two file wire from within a module#262
mrigsby wants to merge 4 commits intocoldbox-modules:developmentfrom
mrigsby:module-view-path-fix

Conversation

@mrigsby
Copy link
Contributor

@mrigsby mrigsby commented Mar 21, 2026

Reference Issue: #261

CBWire is prepending wire/ to the view path and not taking into account if the wire is in a module. This only happens for two file wires, not single file wires.

  • Modified RenderService.cfc method normalizeViewPath() to take a second argument. This argument is the variables._path value in Component.cfc. This is the wire name passed to the wire() method and is used to determine if it contains an @ denoting a module wire.
  • Updated existing normalizeViewPath() tests to account for this second argument
  • Added a new test for normalizeViewPath() to validate for a two file wire from a module path
  • Added a two file wire into the test-harness testingModule
  • Added a test to verify rendering of the view for the two wire module in the test-harness testingModule
  • Passed all tests for all supported engines in local dev (now lets see if they pass on github)
  • and... apparently my vscode removed whitespace in a bunch of places 🤷

@grantcopley grantcopley added this to the v5.0 milestone Mar 23, 2026
@grantcopley grantcopley added the bug Something isn't working label Mar 23, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes rendering of two-file CBWire components that live inside a ColdBox module by preventing incorrect /wires/ prefixing when resolving module view paths (Issue #261).

Changes:

  • Updated RenderService.normalizeViewPath() to accept additional context and adjust when wires/ is prefixed.
  • Updated/added unit and integration tests to cover module-based two-file wire rendering.
  • Added a new two-file wire component + view to the test-harness module.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
models/services/RenderService.cfc Adjusts view path normalization logic to avoid /wires/ being prepended for module-based two-file wires.
models/Component.cfc Passes component _path into normalizeViewPath() when rendering templates.
test-harness/tests/specs/unit/services/RenderServiceSpec.cfc Updates unit tests for the new normalizeViewPath() signature and adds a module two-file wire path test.
test-harness/tests/specs/CBWIRESpec.cfc Adds integration coverage for rendering a two-file module wire via wire().
test-harness/modules_app/testingmodule/wires/twoFileModuleComponent.cfc Adds a two-file module wire component for test coverage.
test-harness/modules_app/testingmodule/wires/twoFileModuleComponent.cfm Adds the paired two-file module wire view for rendering tests.

Comment on lines 174 to 195
@@ -190,7 +190,7 @@ component accessors="true" singleton {
throw( type="CBWIREException", message="A .bxm or .cfm template could not be found for '#arguments.viewPath#'." );
}

if ( left( paths.normalizedPath, 6 ) != "wires/" ) {
if ( !find( "@", arguments.componentPath ) && left( paths.normalizedPath, 6 ) != "wires/" ) {
paths.normalizedPath = "wires/" & paths.normalizedPath;
}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new componentPath-based check (!find( "@", componentPath )) changes normalizeViewPath() behavior for all templates rendered from module components (it will stop auto-prepending wires/ even when viewPath is a normal app wire view). Since module templates already have paths.normalizedPath starting with modules_app/ (from getTemplatePath()), consider keying the prefix decision off the normalized view path (e.g., skip prefix only when it starts with modules_app/), and/or make componentPath optional to avoid breaking callers.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this taking into account also loading wires from external locations as well?

https://cbwire.ortusbooks.com/the-essentials/components#external-components

Comment on lines 230 to 233
function template( viewPath, params = {} ) {
// Normalize the view path
local.normalizedPath = variables._renderService.normalizeViewPath( arguments.viewPath );
local.normalizedPath = variables._renderService.normalizeViewPath( arguments.viewPath, variables._path );
// Render the view content and trim the result
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

template() now always passes variables._path into normalizeViewPath(), but _path is not initialized in onDIComplete() and can be null unless _withPath() has been called. If a component instance calls template() before _withPath(), normalizeViewPath() will receive null and can error when calling find(). Consider defaulting to an empty string when _path is null, or making the new componentPath argument optional/nullable-safe in normalizeViewPath().

Copilot uses AI. Check for mistakes.
Comment on lines +295 to +302
var input = "modules_app.testingModule.wires.twoFileModuleComponent";
// simulate the components variables._path which is what is passed to the wire() method
var component_path = "twoFileModuleComponent@testingModule";
// use full path to module wire
var bxmAbsolutePath = expandPath( "../modules_app/testingModule/wires/twoFileModuleComponent.bxm" );
var cfmAbsolutePath = expandPath( "../modules_app/testingModule/wires/twoFileModuleComponent.cfm" );

var expectedPath = "/modules_app/testingModule/wires/twoFileModuleComponent.cfm";
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new module-path test uses testingModule casing in input, component_path, expandPath(), and expectedPath, but the actual test-harness module directory is modules_app/testingmodule (lowercase). On case-sensitive filesystems this will fail and also doesn't match the integration test which uses @testingmodule. Update these strings/paths to use the correct module name casing and prefer a root-based path (/modules_app/...) to mirror buildViewPaths().

Suggested change
var input = "modules_app.testingModule.wires.twoFileModuleComponent";
// simulate the components variables._path which is what is passed to the wire() method
var component_path = "twoFileModuleComponent@testingModule";
// use full path to module wire
var bxmAbsolutePath = expandPath( "../modules_app/testingModule/wires/twoFileModuleComponent.bxm" );
var cfmAbsolutePath = expandPath( "../modules_app/testingModule/wires/twoFileModuleComponent.cfm" );
var expectedPath = "/modules_app/testingModule/wires/twoFileModuleComponent.cfm";
var input = "modules_app.testingmodule.wires.twoFileModuleComponent";
// simulate the components variables._path which is what is passed to the wire() method
var component_path = "twoFileModuleComponent@testingmodule";
// use full path to module wire
var bxmAbsolutePath = expandPath( "/modules_app/testingmodule/wires/twoFileModuleComponent.bxm" );
var cfmAbsolutePath = expandPath( "/modules_app/testingmodule/wires/twoFileModuleComponent.cfm" );
var expectedPath = "/modules_app/testingmodule/wires/twoFileModuleComponent.cfm";

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0a018fb

grantcopley and others added 3 commits March 23, 2026 11:28
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…onent.cfm

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants