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

JIDEA-183: Use page route to determine whether globe component is loaded #90

Merged
merged 3 commits into from
Nov 15, 2024

Conversation

david-mears-2
Copy link
Contributor

@david-mears-2 david-mears-2 commented Nov 11, 2024

Context: https://mrc-ide.myjetbrains.com/youtrack/issue/JIDEA-183/Make-chart-work-with-v-if

In this PR we (continue to) use Nuxt's 'dynamic imports' feature (hence LazyGlobe, which loads lazily) to determine when to load the Globe component. Till now, it was loading on the About page (as long as largeScreen was true) unnecessarily.

@david-mears-2 david-mears-2 changed the title Use page route to determine whether globe component is loaded JIDEA-183: Use page route to determine whether globe component is loaded Nov 11, 2024
Copy link

codecov bot commented Nov 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 1.39%. Comparing base (5512876) to head (d98c08a).
Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #90      +/-   ##
==========================================
- Coverage    1.62%    1.39%   -0.24%     
==========================================
  Files          54       54              
  Lines      146163   146175      +12     
  Branches      306      310       +4     
==========================================
- Hits         2379     2035     -344     
- Misses     143768   144123     +355     
- Partials       16       17       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@david-mears-2
Copy link
Contributor Author

david-mears-2 commented Nov 11, 2024

  • To do: move the showGlobe computed property to the layout component so the logic about hiding and loading is all in one place.

Copy link
Contributor

@EmmaLRussell EmmaLRussell left a comment

Choose a reason for hiding this comment

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

Thanks for the copious comments - this is a bit twisty so they're very useful!

if (!loadGlobeComponent.value) {
// Set the loadGlobeComponent value here, rather than using a computed property, since the app store initializes with the assumption
// that largeScreen is true, and so using a computed would mean that we always try to load the globe on the initial page load.
loadGlobeComponent.value = appStore.largeScreen && pagesUsingGlobe.includes(route.name as string);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you do this here?

Suggested change
loadGlobeComponent.value = appStore.largeScreen && pagesUsingGlobe.includes(route.name as string);
loadGlobeComponent.value = showGlobe.value;

largeScreen should be set correctly at the point where you check its value here.
Also, this isn't checking globeParameter as showGlobeis, but feels like that's relevant for loading too..

Comment on lines +59 to +62
watch(() => route.name, () => {
setGlobeComponent();
});

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't expect this pick up the case where you start off with a small window (but on a large screen) which you then expand, so globe should load. But it did! 😕 Does it do a reload when the window size changes?

Copy link
Contributor Author

@david-mears-2 david-mears-2 Nov 13, 2024

Choose a reason for hiding this comment

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

Well, if I put in a console.log into this watch, it only fires when I change the route, and correctly not when I change the screen size. What is the confusion?

Copy link
Contributor

@EmmaLRussell EmmaLRussell Nov 14, 2024

Choose a reason for hiding this comment

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

If you start off with a small window/screen, you don't want it to load the globe initially... but then you do want it to load if you expand the window size. Which it does! But I'm not sure how it's doing that when it's not watching for changes to the screen size which would setGlobeComponent to set the loadGlobeComponent value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

onMounted has window.addEventListener("resize", setScreenSize);

setScreenSize runs setGlobeComponent();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and setGlobeComponent sets loadGlobeComponent.value

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, yes, I managed to completely fail to see that line! 👓

@david-mears-2 david-mears-2 merged commit a63c6b7 into main Nov 15, 2024
5 of 6 checks passed
@david-mears-2 david-mears-2 deleted the jidea-183-dont-load-globe-component-on-about-page branch November 15, 2024 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants