Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme sync may cause render loops across different browser tabs #1352

Open
2 tasks done
lancegliser opened this issue Apr 5, 2024 · 3 comments
Open
2 tasks done

Theme sync may cause render loops across different browser tabs #1352

lancegliser opened this issue Apr 5, 2024 · 3 comments
Labels
🐛 bug Something isn't working confirmed This bug was confirmed

Comments

@lancegliser
Copy link

lancegliser commented Apr 5, 2024

  • I have searched the Issues to see if this bug has already been reported
  • I have tested the latest version

Steps to reproduce

Clone reproduction repo. Basically npm create flowbite-react@latest.

  1. Run dev server
  2. Open 2-3 copies in different tabs
  3. Adjust a copy of one window's performance tab to use 6x throttling
  4. Spam the light / dark switcher

Current behavior

The tabs are reading, rerendering, and causing other events to communicate back and forth probably based on local storage hooks. This can cause them to hit infinite loops in all tabs.

ezgif-5-ce03d57c56

Expected behavior

No infinite loops.

Context

The reproduction repo here is very silly. We found this bug in our real application, which renders a number of complex SVG's and other expensive operations. A user had just two tabs open, and was able to cause it with a simple double click on the theme switcher.

I wonder if there's neutral ground to be established by adjusting theme mode auto. Perhaps while it's on auto, it just reads the browser preference only, and never even enables the local storage hooks. Maybe there's an option opt in or out of the local storage hooks?

@SutuSebastian SutuSebastian added 🐛 bug Something isn't working confirmed This bug was confirmed labels Apr 7, 2024
@lancegliser
Copy link
Author

@SutuSebastian Is there any particular direction the Flowbite team might prefer? If I find hours, I could start a PR for discussion.

@SutuSebastian
Copy link
Collaborator

@SutuSebastian Is there any particular direction the Flowbite team might prefer? If I find hours, I could start a PR for discussion.

Feel free to contribute with whatever u can 🔥

@lancegliser
Copy link
Author

No real code yet, but just reviewing what it currently does I have some questions:

  • Why is there both a local storage watcher and an event watcher?
  • I considered using a debounce around handleSetMode, but in automated scenario, it's possible this could break tests. They could test the page, swap dark, test the page, and swap again within the debounce timeout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working confirmed This bug was confirmed
Projects
None yet
Development

No branches or pull requests

2 participants