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

feat: replace useHead with ionic-compatible head implementation #518

Merged
merged 17 commits into from
May 22, 2024

Conversation

CHIBX
Copy link
Contributor

@CHIBX CHIBX commented Feb 22, 2024

I created an utility function, useIonHead, that works almost the same as useHead from unhead, but just with a hack around.
The function provides a way to dispose and patch the created head object just like useHead.
During the process, I realized that tabbed view was a big problem when trying to create this util, and the randomness of the Ionic Hooks. The main issue was leaving from a tabbed view to a non-tabbed view and trying to mantain or destroy state.
Guess What: You can nest useIonHead calls within children components and still retain the same structure after the page it was created on, is brought into view, and it's also fast as well.

resolves #6

I figured out that the author of @vueuse/head, @egoist, suggested that developers should go for the unhead package, and so I decided to create an utility function with unhead, to handle <head></head> tags management accurately, irrespective of the Ionic hooks randomness.

Note: There is also support for nested head calls within components
Copy link

netlify bot commented Feb 22, 2024

Deploy Preview for friendly-lamington-fb5690 canceled.

Name Link
🔨 Latest commit ede24be
🔍 Latest deploy log https://app.netlify.com/sites/friendly-lamington-fb5690/deploys/664e646f34e8000008ed7040

@danielroe
Copy link
Collaborator

This is fantastic! Do you think we should overwrite useHead instead of creating an additional composable?

@CHIBX
Copy link
Contributor Author

CHIBX commented Mar 26, 2024

This is fantastic! Do you think we should overwrite useHead instead of creating an additional composable?

@danielroe Sure, I guess changing the name to useHead would be better for ease when working with ongoing projects

@danielroe danielroe self-requested a review as a code owner May 19, 2024 20:11
Copy link

codecov bot commented May 20, 2024

Codecov Report

Attention: Patch coverage is 3.73832% with 103 lines in your changes are missing coverage. Please review.

Project coverage is 46.65%. Comparing base (f8e27aa) to head (ede24be).
Report is 2 commits behind head on main.

Files Patch % Lines
src/runtime/composables/head.ts 0.00% 99 Missing ⚠️
src/module.ts 57.14% 3 Missing ⚠️
src/runtime/plugins/router.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #518      +/-   ##
==========================================
- Coverage   52.36%   46.65%   -5.72%     
==========================================
  Files          10       11       +1     
  Lines         762      866     +104     
  Branches       37       38       +1     
==========================================
+ Hits          399      404       +5     
- Misses        363      462      +99     

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

@danielroe danielroe changed the title fix for @vueuse/head doesn't function properly with ionic feat: add useIonHead for ionic-compatible head metadata May 20, 2024
Copy link
Collaborator

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

I think the next step would be to write a browser test that asserts the correct title after client navigation, following the pattern here:

https://github.com/danielroe/nuxt-ionic/blob/a45c95693f1fdb8de0be43d7a664db72989effd2/test/e2e/ssr.spec.ts#L27-L36

Is that something you would be happy & able to do?

@CHIBX
Copy link
Contributor Author

CHIBX commented May 20, 2024

I think the next step would be to write a browser test that asserts the correct title after client navigation, following the pattern here:

https://github.com/danielroe/nuxt-ionic/blob/a45c95693f1fdb8de0be43d7a664db72989effd2/test/e2e/ssr.spec.ts#L27-L36

Is that something you would be happy & able to do?

@danielroe I will be able to do this

@CHIBX
Copy link
Contributor Author

CHIBX commented May 22, 2024

@danielroe Already created a new test in the e2e/ion-head.spec.ts file, and also changed useIonHead to useHead with a higher priority.

Made a few more changes to the tests due to timeout and memory consumption from previously ongoing tests, ssr.spec.ts, by closing the open page, shaving off a huge amount of allocated memory.

I added delays after each toggle of the button in the test to represent the delay that useHead takes to rectify changes to the document's head tag, but this brought about a reason to increase the timeout for the test.

I hope the test satisfies the required condition

@danielroe danielroe mentioned this pull request May 22, 2024
@danielroe danielroe changed the title feat: add useIonHead for ionic-compatible head metadata feat: replace useHead with ionic-compatible head implementation May 22, 2024
Copy link
Collaborator

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

Thank you so much for this ❤️

@danielroe
Copy link
Collaborator

cc: @harlan-zw - you may have a better idea or improvements to suggest

@danielroe danielroe merged commit b9a4f97 into nuxt-modules:main May 22, 2024
6 of 8 checks passed
Copy link
Contributor Author

@CHIBX CHIBX left a comment

Choose a reason for hiding this comment

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

@danielroe Thanks for correcting the test. This obviously looks better.

@harlan-zw
Copy link

I'm not entirely sure I understand the issue, the Ionic lifecycle hooks don't align with the Vue lifecycle hooks?

If you have any capacity to make an issue on the Unhead repo with some technical background I'd be happy to explore some alternative ways of solving it that don't rely on new composables.

This solution seems quite good though, nice job!

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.

fix: @vueuse/head doesn't function properly with ionic
4 participants