drab icon indicating copy to clipboard operation
drab copied to clipboard

Liveview cohabitation

Open guidotripaldi opened this issue 5 years ago • 12 comments

Currently it is not possible to use both Drab and LiveView in the same application because Drab.Client.generate_drab_js/3 rises when it tries to get the controller module for a LiveView page, since a :phoenix_controller is not present in the conn of a page rendered by LiveView.

Namely, we have to check against the availability of a Controller before to try to access it instead of blindly assume that it is always available, as it was true in the world before the advent of LV.

This patch introduces two new helpers, get_controller_module/1 and get_controller_action_name/1, that let Drab.Client.generate_drab_js/3 to conditionally access the Controller data, and thus generating the Drab js, only when the Controller is actually available.

guidotripaldi avatar Aug 14 '19 14:08 guidotripaldi

I'll leave this for a day for anyone else to look over as I have not ran LiveView and Drab at the same time, remind me if I miss it. ^.^

It would be nice to get a test case for this with LiveView though!

OvermindDL1 avatar Aug 14 '19 18:08 OvermindDL1

It would be nice to get a test case for this with LiveView though!

test added.

guidotripaldi avatar Aug 15 '19 15:08 guidotripaldi

Those look really good, I'll go over them the next time I get a minute, probably tomorrow, thanks! :-)

OvermindDL1 avatar Aug 15 '19 21:08 OvermindDL1

Looks great, however some tests aren't passing, I'm looking over them currently... Test seed: 509794

I don't think this one is related:

15:35:14.711 [warn] element click intercepted: Element <button id="_drab_modal_button_addtional" name="additional" type="button" class="btn btn-default drab-modal-button" data-dismiss="modal">...</button> is not clickable at point (647, 210). Other element would receive the click: <button name="ok" type="submit" class="btn btn-primary drab-modal-button" data-dismiss="modal">...</button>                                                                                             
  (Session info: headless chrome=76.0.3809.100)                                                                                       
  (Driver info: chromedriver=76.0.3809.100 (ed9d447d30203dc5069e540f05079e493fc1c132-refs/branch-heads/3809@{#990}),platform=Linux 4.4.0-140-generic x86_64)                                                                                                                


  1) test Drab.Modal modal over modal (DrabTestApp.ModalTest)
     test/integration/modal_test.exs:92
     Assertion with == failed
     code:  assert visible_text(find_element(:id, "modal5_out")) == "{:additional, %{}}"
     left:  ""
     right: "{:additional, %{}}"
     stacktrace:
       test/integration/modal_test.exs:96: (test)

These aren't failures, but are definitely noisy and do seem very liveview related:

15:35:22.362 [error] GenServer #PID<0.2433.0> terminating
** (MatchError) no match of right hand side value: :external                                                                          
    lib/phoenix_live_view/channel.ex:152: Phoenix.LiveView.Channel.call_mount_handle_params/2                                         
    lib/phoenix_live_view/channel.ex:443: Phoenix.LiveView.Channel.verified_mount/9                                                   
    (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4                                                                           
    (stdlib) gen_server.erl:711: :gen_server.handle_msg/6                                                                             
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3                                                                            
Last message: {:mount, Phoenix.LiveView.Channel}                                                                                      
15:35:22.363 [error] an exception was raised:                                                                                         
    ** (MatchError) no match of right hand side value: :external                                                                      
        lib/phoenix_live_view/channel.ex:152: Phoenix.LiveView.Channel.call_mount_handle_params/2                                     
        lib/phoenix_live_view/channel.ex:443: Phoenix.LiveView.Channel.verified_mount/9                                               
        (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4                                                                       
        (stdlib) gen_server.erl:711: :gen_server.handle_msg/6                                                                         
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3  

And idea what's causing this? I haven't look at the liveview code yet.

And another failure that I don't think is liveview related:

  2) test enabled element should disable after close (DrabTestApp.CoreTest)
     test/integration/core_test.exs:213
     Expected false or nil, got true
     code: refute element_enabled?(find_element(:id, "core1_button"))
     arguments:

         # 1
         %Hound.Element{uuid: "0.3055531904403481-3"}

     stacktrace:
       test/integration/core_test.exs:216: (test)

     The following output was logged:
     15:36:42.960 [error] Browser reports: Drab attribute value 'wrong' is incorrect.
     
     15:36:42.960 [error] Browser reports: Drab attribute value 'wrong.' is incorrect.
     
     15:36:42.960 [error] Browser reports: Drab attribute value 'wrong:' is incorrect.
     
     15:36:42.960 [error] Browser reports: Drab attribute value ':wrong' is incorrect.
     
     15:36:42.961 [error] Browser reports: Drab attribute value '.' is incorrect.
     
     15:36:43.322 [error] Browser reports: Drab attribute value 'wrong' is incorrect.
     
     15:36:43.322 [error] Browser reports: Drab attribute value 'wrong.' is incorrect.
     
     15:36:43.322 [error] Browser reports: Drab attribute value 'wrong:' is incorrect.
     
     15:36:43.323 [error] Browser reports: Drab attribute value ':wrong' is incorrect.
     
     15:36:43.323 [error] Browser reports: Drab attribute value '.' is incorrect.

So it looks like the liveview test is printing error messages, something not being cleaned up perhaps.

As for the two actual failures, they don't look related to this liveview work, though definitely need to look at those.

Would you be able to fix the middle message that isn't a failure but that prints out death messages about liveview stuff? :-)

OvermindDL1 avatar Aug 16 '19 21:08 OvermindDL1

Not liveview related changes post:

Some more testing shows that the first error at test/integration/modal_test.exs:92 sometimes fails and sometimes succeeds, a race condition I'm guessing.

The second error of test/integration/core_test.exs:213 is failing every time however (at least the 6 times of running it). Any ideas @grych?

OvermindDL1 avatar Aug 16 '19 21:08 OvermindDL1

some tests aren't passing, I'm looking over them currently... Test seed: 509794

I cannot find seed 509794, to which build job is it related? I can find an "test Drab.Modal modal over modal (DrabTestApp.ModalTest)" error only in job #356.2, but it seems to be caused by the peculiar elixir/erlang versions combination. Same consideration for the other Travis errors. So we could just change the travis configuration in .travis.yml adding the, currently missing, excludes matrix, something like that (not tried yet, copied from phoenix ):

elixir:
  - 1.6
  - 1.7
  - 1.8
  - 1.9
otp_release:
  - 20.3
  - 21.0
  - 22.0
matrix:
  exclude:
    - elixir: 1.6
      otp_release: 21.0
    - elixir: 1.6
      otp_release: 22.0
    - elixir: 1.7
      otp_release: 19.3
    - elixir: 1.7
      otp_release: 20.3
    - elixir: 1.8
      otp_release: 19.3
    - elixir: 1.8
      otp_release: 20.3
    - elixir: 1.9
      otp_release: 19.3
    - elixir: 1.9
      otp_release: 20.3

guidotripaldi avatar Aug 17 '19 08:08 guidotripaldi

509794

Oh the seed number is the mix test rng seed for ordering. It doesn't matter for the liveview stuff being printed, it happens every time as far as I saw.

error only in job #356.2, but it seems to be caused by the peculiar elixir/erlang versions combination.

Interesting... I'm running 1.8.1 on OTP 21.

So we could just change the travis configuration in .travis.yml adding the, currently missing, excludes matrix, something like that (not tried yet, copied from phoenix)

It sucks even more because it seems to be a race condition, always so hard to diagnose...

OvermindDL1 avatar Aug 19 '19 16:08 OvermindDL1

It sucks even more because it seems to be a race condition, always so hard to diagnose...

It seems an erratic problem peculiar to Travis, independent from the changes we made on Drab

guidotripaldi avatar Aug 20 '19 10:08 guidotripaldi

I mean more related to some of the existing failures unrelated to this PR, they happen sometimes locally, but not others. ^.^;

The LV error messages, no test failure, probably just something not being cleaned up after tests?

OvermindDL1 avatar Aug 20 '19 15:08 OvermindDL1

I don't understand why Travis complaints. Locally I never get across those errors when testing with that elixir/erlang version combination. Maybe its platform dependent, but it shouldn't. Any hints?

guidotripaldi avatar Sep 06 '19 09:09 guidotripaldi

I don't understand why Travis complaints. Locally I never get across those errors when testing with that elixir/erlang version combination. Maybe its platform dependent, but it shouldn't. Any hints?

It's with the tests, the LiveView socket isn't being cleaned up properly still is what these mean:

13:16:45.127 [error] GenServer #PID<0.2335.0> terminating
** (MatchError) no match of right hand side value: :external
    lib/phoenix_live_view/channel.ex:152: Phoenix.LiveView.Channel.call_mount_handle_params/2
    lib/phoenix_live_view/channel.ex:443: Phoenix.LiveView.Channel.verified_mount/9
    (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:711: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: {:mount, Phoenix.LiveView.Channel}
13:16:45.129 [error] an exception was raised:
    ** (MatchError) no match of right hand side value: :external
        lib/phoenix_live_view/channel.ex:152: Phoenix.LiveView.Channel.call_mount_handle_params/2
        lib/phoenix_live_view/channel.ex:443: Phoenix.LiveView.Channel.verified_mount/9
        (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
        (stdlib) gen_server.erl:711: :gen_server.handle_msg/6
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

And this error is some issue with the embedded browser testing, which I've not done much of yet, so I'm unsure. Anyone have ideas?

  1) test enabled element should disable after close (DrabTestApp.CoreTest)
     test/integration/core_test.exs:213
     Expected false or nil, got true
     code: refute element_enabled?(find_element(:id, "core1_button"))
     arguments:
         # 1
         %Hound.Element{uuid: "0.08030434519235863-3"}
     stacktrace:
       test/integration/core_test.exs:216: (test)
     The following output was logged:
     13:17:32.873 [error] Browser reports: Drab attribute value 'wrong' is incorrect.
     
     13:17:32.873 [error] Browser reports: Drab attribute value 'wrong.' is incorrect.
     
     13:17:32.873 [error] Browser reports: Drab attribute value 'wrong:' is incorrect.
     
     13:17:32.873 [error] Browser reports: Drab attribute value ':wrong' is incorrect.
     
     13:17:32.873 [error] Browser reports: Drab attribute value '.' is incorrect.
     
     13:17:33.221 [error] Browser reports: Drab attribute value 'wrong' is incorrect.
     
     13:17:33.221 [error] Browser reports: Drab attribute value 'wrong.' is incorrect.
     
     13:17:33.221 [error] Browser reports: Drab attribute value 'wrong:' is incorrect.
     
     13:17:33.221 [error] Browser reports: Drab attribute value ':wrong' is incorrect.
     
     13:17:33.221 [error] Browser reports: Drab attribute value '.' is incorrect.

OvermindDL1 avatar Sep 06 '19 14:09 OvermindDL1

Any thoughts as to the sporadic error that pops up from liveview in the tests?

OvermindDL1 avatar Sep 17 '19 14:09 OvermindDL1