This repository was archived by the owner on Oct 19, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +33
-4
lines changed Expand file tree Collapse file tree 3 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -174,9 +174,9 @@ def self.convert_props(properties)
174
174
elsif key == 'ref' && value . is_a? ( Proc )
175
175
props [ key ] = %x{
176
176
function(dom_node){
177
- if (dom_node.__opalInstance !== undefined && dom_node.__opalInstance !== null) {
177
+ if (dom_node !== null && dom_node .__opalInstance !== undefined && dom_node.__opalInstance !== null) {
178
178
#{ value . call ( `dom_node.__opalInstance` ) } ;
179
- } else if(ReactDOM.findDOMNode !== undefined && dom_node.nodeType === undefined) {
179
+ } else if(dom_node !== null && ReactDOM.findDOMNode !== undefined && dom_node.nodeType === undefined) {
180
180
#{ value . call ( `ReactDOM.findDOMNode(dom_node)` ) } ;
181
181
} else {
182
182
#{ value . call ( `dom_node` ) } ;
Original file line number Diff line number Diff line change @@ -14,9 +14,9 @@ def self.convert_props(properties)
14
14
props . map do |key , value |
15
15
if key == "ref" && value . is_a? ( Proc )
16
16
new_proc = Proc . new do |native_inst |
17
- if `#{ native_inst } .__opalInstance !== undefined && #{ native_inst } .__opalInstance !== null`
17
+ if `#{ native_inst } !== null && #{ native_inst } .__opalInstance !== undefined && #{ native_inst } .__opalInstance !== null`
18
18
value . call ( `#{ native_inst } .__opalInstance` )
19
- elsif `ReactDOM.findDOMNode !== undefined && #{ native_inst } .nodeType === undefined`
19
+ elsif `#{ native_inst } !== null && ReactDOM.findDOMNode !== undefined && #{ native_inst } .nodeType === undefined`
20
20
value . call ( `ReactDOM.findDOMNode(#{ native_inst } )` ) # react >= v0.15.`)
21
21
else
22
22
value . call ( native_inst )
Original file line number Diff line number Diff line change @@ -62,4 +62,33 @@ def render
62
62
"#{ Foo . bar . JS [ 'nodeType' ] } " # aboids json serialisation errors by using "#{}"
63
63
end . to eq ( "1" )
64
64
end
65
+
66
+ it "works, even when the component is unmounted" do
67
+ # was a bug, on umount react calls the ref method with null instead of a dom node
68
+ # callback failed then
69
+ # ref is called two times, once on mount with dom_node, once on unmount with null
70
+ mount "Foo" do
71
+ class Unmountable < Hyperloop ::Component
72
+ render do
73
+ DIV { "This is a Component" }
74
+ end
75
+ end
76
+ Foo . class_eval do
77
+ def ref_rec ( dom_node )
78
+ @@rec_cnt ||= 0
79
+ @@rec_cnt += 1
80
+ end
81
+ def self . rec_cnt
82
+ @@rec_cnt
83
+ end
84
+
85
+ after_mount { mutate . unmount true }
86
+
87
+ render do
88
+ Unmountable ( ref : method ( :ref_rec ) . to_proc ) unless state . unmount
89
+ end
90
+ end
91
+ end
92
+ expect_evaluate_ruby ( 'Foo.rec_cnt' ) . to eq ( 2 )
93
+ end
65
94
end
You can’t perform that action at this time.
0 commit comments