FLUID-6126: Failure when using fluid.construct to construct component as direct child of root which is target of a distribution

Metadata

Source
FLUID-6126
Type
Bug
Priority
Major
Status
Closed
Resolution
Fixed
Assignee
Antranig Basman
Reporter
Antranig Basman
Created
2017-02-08T21:22:48.623-0500
Updated
2017-02-09T10:33:02.708-0500
Versions
  1. 2.0
Fixed Versions
N/A
Component
  1. IoC System

Description

An annoying edge case creates a bad interaction between fluid.construct and fluid.computeDistributionPriority -> fluid.getMemberNames.

If there is a global distribution which is capable of hitting components which are directly attached to the root, e.g.

fluid.defaults("fluid.authoring.nexus.componentTracker", {
    gradeNames: ["fluid.component", "fluid.resolveRoot"],
    distributeOptions: {
        modelTracker: {
            record: "fluid.authoring.nexus.modelTracker",
            target: "{/ fluid.modelComponent}.options.gradeNames"
        }
    }
});

using fluid.construct, say, with a path of "sample-model-component-0" to construct a component directly attached to the root will trigger a failure

TypeError: Cannot read property 'id' of undefined
    at Object.fluid.getMemberNames (E:\\source\\gits\\fluid-authoring\\node_modules\\infusion\\src\\framework\\core\\js\\FluidIoC.js:87:73)

since we don't handle the case where the path stack is empty. fluid.getMemberNames is pretty suspect anyway and has been ripe for fencepost errors for many years:

fluid.getMemberNames = function (instantiator, thatStack) {
        var path = instantiator.idToPath(thatStack[thatStack.length - 1].id);
        var segs = instantiator.parseEL(path);
            // TODO: we should now have no longer shortness in the stack
        segs.unshift.apply(segs, fluid.generate(thatStack.length - segs.length, ""));

        return segs;
    };

Comments