hyperstack-org / hyperstack-org/hyperstack

WhileLoading edge cases

Đang mở
#256 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
JavaScript
Star
538
Fork
41
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.