Skip to content

Commit 513d18d

Browse files
committed
Fixed double state discard bug.
Fixed a bug where when a widget was refreshed, it's state would be discarded twice causing the new widget to not be connected to any state objects.
1 parent 8f9d9b2 commit 513d18d

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/Internal.lua

+10-10
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ return function(Iris: Types.Iris): Types.Internal
190190
end
191191

192192
for _, widget: Types.Widget in Internal._lastVDOM do
193-
if widget.lastCycleTick ~= Internal._cycleTick then
193+
if widget.lastCycleTick ~= Internal._cycleTick and (widget.lastCycleTick ~= -1) then
194194
-- a widget which used to be rendered was not called last frame, so we discard it.
195+
-- if the cycle tick is -1 we have already discarded it.
195196
Internal._DiscardWidget(widget)
196197
end
197198
end
@@ -404,7 +405,6 @@ return function(Iris: Types.Iris): Types.Internal
404405
find the previous frame widget if it exists. If no widget exists, a new one is created.
405406
]=]
406407
function Internal._Insert(widgetType: string, args: Types.WidgetArguments?, states: Types.WidgetStates?): Types.Widget
407-
local thisWidget: Types.Widget
408408
local ID: Types.ID = Internal._getID(3)
409409
--debug.profilebegin(ID)
410410

@@ -430,19 +430,19 @@ return function(Iris: Types.Iris): Types.Internal
430430
-- prevents tampering with the arguments which are used to check for changes.
431431
table.freeze(arguments)
432432

433-
if Internal._lastVDOM[ID] and widgetType == Internal._lastVDOM[ID].type then
433+
local lastWidget: Types.Widget? = Internal._lastVDOM[ID]
434+
if lastWidget and widgetType == lastWidget.type then
434435
-- found a matching widget from last frame.
435436
if Internal._localRefreshActive then
436437
-- we are redrawing every widget.
437-
Internal._DiscardWidget(Internal._lastVDOM[ID])
438-
else
439-
thisWidget = Internal._lastVDOM[ID]
438+
Internal._DiscardWidget(lastWidget)
439+
-- so we don't accidentally discard it twice
440+
lastWidget.lastCycleTick = -1
441+
lastWidget = nil
440442
end
441443
end
442-
if thisWidget == nil then
443-
-- didnt find a match, generate a new widget.
444-
thisWidget = Internal._GenNewWidget(widgetType, arguments, states, ID)
445-
end
444+
local thisWidget: Types.Widget = if lastWidget == nil then Internal._GenNewWidget(widgetType, arguments, states, ID) else lastWidget
445+
446446
local parentWidget: Types.Widget = thisWidget.parentWidget
447447

448448
if thisWidget.type ~= "Window" and thisWidget.type ~= "Tooltip" then

lib/Types.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export type Arguments = {
6666

6767
export type State = {
6868
value: any,
69-
ConnectedWidgets: { [ID]: string },
69+
ConnectedWidgets: { [ID]: Widget },
7070
ConnectedFunctions: { (any) -> () },
7171

7272
get: (self: State) -> any,

0 commit comments

Comments
 (0)