hyperstack-org / hyperstack-org/hyperstack

WhileLoading edge cases

未关闭
#256 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
JavaScript
星标
538
派生
41
PR 合并指标
30 天内没有已合并 PR

描述

In more complicated scenarios WhileLoading is failing:

1) If the same component class is mounted in various places on the display.
2) Sometimes the while loading state can be left as waiting for loading, when the loading has completed. (this is hard to reproduce)

Patches look like this:

```ruby
module Hyperstack
module Internal
module Component
class WhileLoadingWrapper < RescueWrapper
render do
if @waiting_on_resources && !quiet?
RenderingContext.raise_if_not_quiet = false
else
@waiting_on_resources = false
@Child.instance_eval do
mutate if @__hyperstack_while_loading_waiting_on_resources
@__hyperstack_while_loading_waiting_on_resources = false
end
RenderingContext.raise_if_not_quiet = self # <---- save self as part of the context
end
RescueMetaWrapper(children_elements: @ChildrenElements)
end

# if you want to apply this patch you will need to clear the existing before mount callback
send("_before_mount_callbacks").clear

before_mount do
@Child.class.rescues RenderingContext::NotQuiet do |e|
# pass the rescue wrapper back in as part of the exception
e.while_loading_rescue_wrapper.instance_variable_set(:@waiting_on_resources, true)
@__hyperstack_while_loading_waiting_on_resources = true
end
end

after_render do
# after each render clear the raise if not quiet
RenderingContext.raise_if_not_quiet = false
end
end
end
end
end

module Hyperstack
module Internal
module Component
class RenderingContext
class NotQuiet < Exception
# add the while loading instance to the error so we can use it in the rescue
attr_reader :while_loading_rescue_wrapper
def initialize(component, wrapper)
@while_loading_rescue_wrapper = wrapper
super("#{component} is waiting on resources - this should never happen")
end
end
class << self
attr_accessor :waiting_on_resources

def raise_if_not_quiet?
@while_loading_rescue_wrapper
end

def raise_if_not_quiet=(wrapper)
@while_loading_rescue_wrapper = wrapper
end

def quiet_test(component)
return unless component.waiting_on_resources && raise_if_not_quiet? #&& component.class != RescueMetaWrapper <- WHY can't create a spec that this fails without this, but several fail with it.
# raise the error with the current rescue wrapper context
raise NotQuiet.new(component, @while_loading_rescue_wrapper)
end
end
end
end
end
end
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。