Skip to content

Commit d398fd3

Browse files
committed
fixes two regressions, one to go
1 parent fdd8efc commit d398fd3

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

ruby/hyper-component/lib/hyperstack/component/element.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ def on(*event_names, &block)
5858
# Used for elements that are not yet in DOM, i.e. they are provided as children
5959
# or they have been explicitly removed from the rendering context using the delete method.
6060

61-
def render(*props, &new_block)
61+
def render(*props)
6262
if props.empty?
6363
Hyperstack::Internal::Component::RenderingContext.render(self)
6464
else
65-
props = Hyperstack::Internal::Component::ReactWrapper.convert_props(*props)
65+
props = Hyperstack::Internal::Component::ReactWrapper.convert_props(@type, @properties, *props)
6666
@_child_element = Hyperstack::Internal::Component::RenderingContext.render(
6767
Element.new(`React.cloneElement(#{@native}, #{props.shallow_to_n})`,
68-
type, @properties.merge(props), block)
68+
type, props, block)
6969
)
7070
end
7171
end

ruby/hyper-component/lib/hyperstack/internal/component/haml.rb

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def method_missing(class_name, args = {}, &new_block)
2727
Hyperstack::Internal::Component::RenderingContext.replace(
2828
self,
2929
Hyperstack::Internal::Component::RenderingContext.build do
30-
Hyperstack::Internal::Component::RenderingContext.render(type, build_new_properties(class_name, args), &new_block)
30+
Hyperstack::Internal::Component::RenderingContext.render(
31+
type, @properties, args, class: haml_class_name(class_name), &new_block
32+
)
3133
end
3234
)
3335
end
@@ -39,17 +41,6 @@ def rendered?
3941
def haml_class_name(class_name)
4042
class_name.gsub(/__|_/, '__' => '_', '_' => '-')
4143
end
42-
43-
private
44-
45-
def build_new_properties(class_name, args)
46-
class_name = haml_class_name(class_name)
47-
new_props = @properties.dup
48-
new_props[:className] = "\
49-
#{class_name} #{new_props[:className]} #{args.delete(:class)} #{args.delete(:className)}\
50-
".split(' ').uniq.join(' ')
51-
new_props.merge! args
52-
end
5344
end
5445
end
5546
end

ruby/hyper-component/lib/hyperstack/internal/component/react_wrapper.rb

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,22 @@ def self.convert_props(type, *args)
262262
"If you want to capture the ref in an instance variable use the `set` method.\n"\
263263
"For example `ref: set(:TheRef)` will capture assign the ref to `@TheRef`\n"
264264
end
265-
props[key] = %x{
266-
function(dom_node){
267-
if (dom_node !== null && dom_node.__opalInstance !== undefined && dom_node.__opalInstance !== null) {
268-
#{ Hyperstack::Internal::State::Mapper.ignore_mutations { value.call(`dom_node.__opalInstance`) } };
269-
} else if(dom_node !== null && ReactDOM.findDOMNode !== undefined && dom_node.nodeType === undefined) {
270-
#{ Hyperstack::Internal::State::Mapper.ignore_mutations { value.call(`ReactDOM.findDOMNode(dom_node)`) } };
271-
} else if(dom_node !== null){
272-
#{ Hyperstack::Internal::State::Mapper.ignore_mutations { value.call(`dom_node`) } };
273-
}
274-
}
265+
unless `value.__hyperstack_component_ref_is_already_wrapped`
266+
fn = value
267+
value = %x{
268+
function(dom_node){
269+
if (dom_node !== null && dom_node.__opalInstance !== undefined && dom_node.__opalInstance !== null) {
270+
#{ Hyperstack::Internal::State::Mapper.ignore_mutations { fn.call(`dom_node.__opalInstance`) } };
271+
} else if(dom_node !== null && ReactDOM.findDOMNode !== undefined && dom_node.nodeType === undefined) {
272+
#{ Hyperstack::Internal::State::Mapper.ignore_mutations { fn.call(`ReactDOM.findDOMNode(dom_node)`) } };
273+
} else if(dom_node !== null){
274+
#{ Hyperstack::Internal::State::Mapper.ignore_mutations { fn.call(`dom_node`) } };
275275
}
276-
276+
}
277+
}
278+
`value.__hyperstack_component_ref_is_already_wrapped = true`
279+
end
280+
props[key] = value
277281
elsif key == 'jq_ref'
278282
unless value.respond_to?(:call)
279283
raise "The ref and dom params must be given a Proc.\n"\

ruby/hyper-component/spec/deprecated_features/haml_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Foo < Hyperloop::Component
3131
end
3232
end
3333
end
34-
expect(page.body).to include('<div class="div-class"><span class="other-class the-class">a man walks into a bar</span></div>')
34+
expect(page.body).to include('<div class="div-class"><span class="the-class other-class">a man walks into a bar</span></div>')
3535
end
3636

3737
it 'redefines `p` to make method missing work' do

0 commit comments

Comments
 (0)