hyperstack-org / hyperstack-org/hyperstack

WhileLoading edge cases

Open
#256 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
538
Forks
41
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.