dphfox / Fusion

A modern reactive UI library, built specifically for Roblox and Luau.
https://elttob.uk/Fusion/
MIT License
530 stars 91 forks source link

"The class type 'TextLabel' has no assignable property 'TextColor3'" when using ForValues (and ForPairs) #331

Closed SpiralAPI closed 1 month ago

SpiralAPI commented 1 month ago

Stack trace:

[Fusion] ForValues callback error: [Fusion] The class type 'TextLabel' has no assignable property 'TextColor3'.
        (ID: cannotAssignProperty)
    (ID: forValuesProcessorError)
    ---- Stack trace ----
    ReplicatedStorage.Packages._Index.elttob_fusion@0.2.0.fusion.Logging.logError:29 function logError
    ReplicatedStorage.Packages._Index.elttob_fusion@0.2.0.fusion.Instances.applyInstanceProps:39 function setProperty
    ReplicatedStorage.Packages._Index.elttob_fusion@0.2.0.fusion.Instances.applyInstanceProps:69 function bindProperty
    ReplicatedStorage.Packages._Index.elttob_fusion@0.2.0.fusion.Instances.applyInstanceProps:87 function applyInstanceProps

Code being used:

local Inventory = Fusion.Value({})
local InventoryTemplates = Fusion.ForValues(Inventory, function(Data)
        ...
    return Template({
        Name = SwordName,
        Amount = Amount,
        LayoutOrder = (SwordData.Rarity.Index * -1),
        Color = SwordData.Rarity.Color,
        Visible = true,
        Activated = function() end,
    })
end, function() end)

--//Component
local function Component(props)
    ...
    InventoryTemplates
end

--//Init
local function Update(Data)
    local Final = {}
    for i, v in pairs(Data.Swords or {}) do
        table.insert(Final, {
            Name = i,
            Amount = v,
        })
    end
    Inventory:set(Final)
end
DataReplica.Loaded:Connect(Update)
DataReplica.Updated:Connect(Update)

Line 107 Template.lua

Fusion.New("TextLabel")({
    Name = "Title",
    Font = Enum.Font.GothamBlack,
    Text = props.Name,
    TextColor3 = Color3.fromRGB(255, 255, 255),
    TextScaled = true,
    AnchorPoint = Vector2.new(0.5, 1),
    BackgroundTransparency = 1,
    Position = TitleTween,
    Size = UDim2.fromScale(1, 0.15),
    ZIndex = 5,
}),

Error only seems occurs with For objects

ALSO is worth noting that the reason my cleanup is function() end is because using Fusion.cleanup results in studio crashing!

SpiralAPI commented 1 month ago

Ended up finding the fix; if your using any Fusion.Value objects, make sure to keep them WITHIN your function component block, or else the state will be constantly updated between all places that use that component