Skip to content

fix: theme flickering#16903

Merged
hbjORbj merged 4 commits into
mainfrom
fix/flickering
Oct 15, 2024
Merged

fix: theme flickering#16903
hbjORbj merged 4 commits into
mainfrom
fix/flickering

Conversation

@hbjORbj
Copy link
Copy Markdown
Contributor

@hbjORbj hbjORbj commented Oct 2, 2024

What does this PR do?

  • When app theme is not matching user's computer system theme, there's a flickering due to theme mismatch in a page render

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • N/A - I have added a Docs issue here if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Are there environment variables that should be set?
  • What are the minimal test data to have?
  • What is expected (happy path) to have (input and output)?
  • Any other important info that could help to test that PR

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project
  • I haven't commented my code, particularly in hard-to-understand areas
  • I haven't checked if my changes generate no new warnings

@graphite-app graphite-app Bot requested a review from a team October 2, 2024 07:14
@keithwillcode keithwillcode added consumer core area: core, team members only labels Oct 2, 2024
@dosubot dosubot Bot added ui area: UI, frontend, button, form, input 🐛 bug Something isn't working labels Oct 2, 2024
@graphite-app
Copy link
Copy Markdown

graphite-app Bot commented Oct 2, 2024

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (10/02/24)

1 reviewer was added to this PR based on Keith Williams's automation.

Comment thread apps/web/pages/_document.tsx
emrysal
emrysal previously requested changes Oct 2, 2024
Copy link
Copy Markdown
Contributor

@emrysal emrysal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works - but it also breaks the Booker theme for the logged in user - which is meant to take priority over the dashboard theme.

image

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 2, 2024

E2E results are ready!

@vercel
Copy link
Copy Markdown

vercel Bot commented Oct 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Oct 6, 2024 7:53pm
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Oct 6, 2024 7:53pm

@hbjORbj
Copy link
Copy Markdown
Contributor Author

hbjORbj commented Oct 4, 2024

@emrysal Follow up to our discussion: I improved the vanilla JS logic inside the inline script to take the booking page theme into consideration. I tested and all works fine. Let me know it's the same case in your end!

@emrysal
Copy link
Copy Markdown
Contributor

emrysal commented Oct 7, 2024

@hbjORbj FYI it's all good from the booking's end, just waiting for @hariombalhara to confirm embeds.

@hbjORbj
Copy link
Copy Markdown
Contributor Author

hbjORbj commented Oct 9, 2024

@hariombalhara Can you give this a review?

Comment on lines +72 to +101
(function applyTheme() {
try {
const appTheme = localStorage.getItem('app-theme');
if (!appTheme) return;

let bookingTheme, username;
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key.startsWith('booking-theme:')) {
bookingTheme = localStorage.getItem(key);
username = key.split("booking-theme:")[1];
break;
}
}

const onReady = () => {
const isBookingPage = username && window.location.pathname.slice(1).startsWith(username);

if (document.body) {
document.body.classList.add(isBookingPage ? bookingTheme : appTheme);
} else {
requestAnimationFrame(onReady);
}
};

requestAnimationFrame(onReady);
} catch (e) {
console.error('Error applying theme:', e);
}
})();
Copy link
Copy Markdown
Member

@hariombalhara hariombalhara Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add some unit tests for this. We could make it a function and use fn.toString() here.

This logic works in combination with app-providers-app-dir.tsx. So, if possible we should share constants b/w them e.g. 'booking-theme' prefix.

Also, I am not clear why we need to add this logic here. Doesn't AppProviders stuff work now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No; at the moment there's a brief moment between pageload and app render where it decides on the wrong theme (only when dark mode is selected)

Copy link
Copy Markdown
Contributor

@emrysal emrysal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🌑

@hbjORbj hbjORbj merged commit 4037367 into main Oct 15, 2024
@hbjORbj hbjORbj deleted the fix/flickering branch October 15, 2024 10:13
@hbjORbj hbjORbj mentioned this pull request Dec 14, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working consumer core area: core, team members only ready-for-e2e ui area: UI, frontend, button, form, input

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants