lookbook-hq / lookbook

A UI development environment for Ruby on Rails apps ✨
https://lookbook.build
MIT License
913 stars 94 forks source link

Previews not updating after navigation in production #344

Closed NYDrewReynolds closed 1 year ago

NYDrewReynolds commented 1 year ago

Describe the bug

When using Lookbook in production, the preview frame doesn't update when navigating using the sidebar. It requires a full page refresh to fetch the new previews.

To Reproduce

Steps to reproduce the behavior:

  1. Go to Lookbook in a production URL
  2. Click on any preview other than what you're currently looking at
  3. See that the URL updates but the preview frame remains the same.

Expected behavior

I'd expect the preview frame to update.

Screen-recording

https://user-images.githubusercontent.com/2224702/221275991-f00c36b5-8143-443f-94ff-727a33676688.mov

Version numbers

Please complete the following information:

beneggett commented 1 year ago

I've noticed the same if using Rails caching in production.

Rails.cache.delete_matched("views/layouts/lookbook/*")

Should clear it up

allmarkedup commented 1 year ago

@NYDrewReynolds Thanks for the bug report and video - very helpful, nice one. It definitely seems like a caching issue but I'm not sure why it's just the preview contents that are affected. The only explicit fragment caching Lookbook does in production is of the sidebar menu so I'm not sure what's going on here.

@beneggett thanks for posting up your workaround - where/when are you running that code out of interest?

I'll dive into this a bit more when I have a little more time and try to stop this from happening in the first place but in the meantime @NYDrewReynolds I'd be interested to know if @beneggett's suggestion works for you.

NYDrewReynolds commented 1 year ago

@allmarkedup Unfortunately @beneggett's suggestion didn't work for me and I also had an interesting development. I'm only having this issue in Firefox. I tried clearing my cache and any data and it still continues to happen in that browser.

beneggett commented 1 year ago

@allmarkedup - I'll post more details / video, when i get a chance. Currently on 1.5.1.

It's pretty easy to replicate in dev from what I recall, considering you have something like this in your development.rb file

  # Enable/disable caching. By default caching is disabled.
  # Run rails dev:cache to toggle caching.
  if Rails.root.join("tmp", "caching-dev.txt").exist?
    config.action_controller.perform_caching = true
    config.action_controller.enable_fragment_cache_logging = true

    config.cache_store = :memory_store
    config.public_file_server.headers = {
      "Cache-Control" => "public, max-age=#{2.days.to_i}"
    }

Using Redis as memory store for action_controller caching, I found that the sidebar items get cached / remembered, and if you start changing things around (e.g. using @logical_path and moving components from one virtual directory to another), changes / new additions / modifications, etc. Don't get picked up and you get into some funny states.

I'll try and make a video in the next few days

allmarkedup commented 1 year ago

@NYDrewReynolds okay yes that is interesting! I'll take a look and see if the same thing happens to me. It may be that I need to update the iframe differently somehow to ensure that Firefox picks up on the changes correctly.

allmarkedup commented 1 year ago

@beneggett Ah okay, yes the sidebar does get cached, and there was a bug where the cache was not expiring when changes were detected. That should be fixed (crudely!) in v1.5.3 - could you give it a try when you have a chance and let me know if that solves the issue for you?

allmarkedup commented 1 year ago

@NYDrewReynolds So I've not been able to recreate this at all unfortunately, But I've just released a new beta that has a precautionary change in it that I hope may fix the issue even if I can't replicate in here. Can you let me know how you get on if you get a chance to try it?

@beneggett Possibly of interest to you: the latest beta also does away with the sidebar fragment cache altogether as it has been causing too many problems for people. I may revisit it in the future but this new version is much more efficient at generating the nav that the 1.x versions so it may not be necessary any more.

allmarkedup commented 1 year ago

@NYDrewReynolds As I haven't heard back I'm going to go ahead and close this issue. I've not been able to replicate it at my end but if it's still a problem in the latest beta release please feel free to reopen and let me know. Thanks :-)

NYDrewReynolds commented 1 year ago

@allmarkedup The new beta version did the trick for us! Thank you!

allmarkedup commented 1 year ago

@NYDrewReynolds Ah fantastic, thanks for letting me know. Glad it's working now :-)