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: load favicon from WordPress server #119

Merged
merged 19 commits into from
Mar 19, 2025

Conversation

SH4LIN
Copy link
Collaborator

@SH4LIN SH4LIN commented Mar 5, 2025

What

  • This PR will load the favicon icon, apple touch icon and msapplication-tileImage from the WordPress server

Related Issue(s):

How

  • This PR will use the app router metadata API and using that metadata API and the icon data fetched from server it will add the necessary tags into the head

Checklist

  • I have read the Contribution Guidelines.
  • My code is tested to the best of my abilities.
  • My code passes all lints (ESLint, tsc, prettier etc.).
  • My code has detailed inline documentation.
  • I have added unit tests to verify the code works as intended.
  • I have updated the project documentation as needed.
  • I have added a changeset for this PR using npm run changeset.

Copy link

changeset-bot bot commented Mar 5, 2025

🦋 Changeset detected

Latest commit: 7fea521

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@snapwp/query Patch
@snapwp/next Patch
snapwp Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@SH4LIN SH4LIN requested review from justlevine and ayushnirwal March 5, 2025 05:34
@SH4LIN SH4LIN self-assigned this Mar 5, 2025
@SH4LIN SH4LIN requested a review from ayushnirwal March 5, 2025 08:49
ayushnirwal
ayushnirwal previously approved these changes Mar 5, 2025
Copy link
Collaborator

@ayushnirwal ayushnirwal left a comment

Choose a reason for hiding this comment

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

LGTM

…ifferent size of Icon as favicon, 180x180 res icon as apple touch icon and 270x270 as msApplicationTileImage
@SH4LIN SH4LIN requested a review from ayushnirwal March 6, 2025 08:02
@SH4LIN SH4LIN changed the title fix: interim solution to stop browser from making a request to /favicon.ico feature: load favicon from WordPress server Mar 6, 2025
@SH4LIN SH4LIN requested a review from ayushnirwal March 6, 2025 08:32
@ayushnirwal ayushnirwal requested review from Ta5r and removed request for Ta5r March 6, 2025 12:12
Copy link
Collaborator

@justlevine justlevine left a comment

Choose a reason for hiding this comment

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

Functionally working 🚀

Feedback on composability/code quality patterns below:

@justlevine justlevine changed the title feature: load favicon from WordPress server feat: load favicon from WordPress server Mar 9, 2025
@SH4LIN SH4LIN requested a review from justlevine March 13, 2025 19:16
Copy link
Collaborator

@justlevine justlevine left a comment

Choose a reason for hiding this comment

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

Functionally, things are passing, but I would like @ayushnirwal 's feedback on the composability (generally, and per the open conversations on this diff).

Once that's done (since the package diff might change) npm run changeset and we should be able to merge this.

Copy link
Collaborator

@ayushnirwal ayushnirwal left a comment

Choose a reason for hiding this comment

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

Although the patterns around queries, documents, client management are not ideal in the current state. I'm willing to merge this PR (after the last few feedbacks are addressed) for the following reasons.

  • It works.
  • This adds parsers, some of the types around favicon and meta data management. When we implement the metadata management and data fetching management interfaces these will be used.

@justlevine
Copy link
Collaborator

Although the patterns around queries, documents, client management are not ideal in the current state. I'm willing to merge this PR

@ayushnirwal can you flag some parts of the diff that deserve a // @todo and/or generally list what the next steps should theoretically be for improving things?

I don't want to merge this PR without making sure we have a (vague) plan to follow it up.

@ayushnirwal
Copy link
Collaborator

import type { DocumentNode, TypedQueryDocumentNode } from 'graphql';

export type Variables = Record< string, unknown >;

export type FetchQuery< T = unknown, V extends Variables = Variables > = (
	queryKey: string[],
	document: DocumentNode | TypedQueryDocumentNode< T, V >
) => Promise< T >;

export type getServerClient = (
	url: string,
	options: Record< string, unknown >
) => ServerClient;

export type getBrowserClient = (
	url: string,
	options: Record< string, unknown >
) => BrowserClient;

export interface ServerClient {
	fetchQuery: FetchQuery;
}

export interface BrowserClient {}

These types/interfaces are the general broad strokes for the composability in our data-fetching mechanisms. This allows users to

  • Implement their own ServerClient with the custom getServerClient and fetchQuery
  • Compose their own ServerClient with the getServerClient and fetchQuery with implementations exported from @snapwp/query
  • Use a pre-implemented ServerClient exported from @snapwp/query
  • Any implementation of ServerClient will have the fetchQuery function to which a doc can be passed for querying.
  • Wrappers will be built around FetchQuery to get functions like FetchGlobalStyles. These will be exported for internal or external use.

@justlevine
Copy link
Collaborator

@ayushnirwal anything specific to favicons / site metadata (see the remaining open conversations on this PR) or just the underlying Query API?

@ayushnirwal
Copy link
Collaborator

Wrappers will be built around FetchQuery to get functions like FetchGlobalStyles. These will be exported for internal or external use.

  • Similar to this we will create a wrapper FetchFaviconDetails
  • getIcons (without the fetch call) and its internal utilities become data parsing utilities. Which allows us to move it to @snapwp/core along with the related types.
  • FetchFaviconDetails and renamed getIcons will be then composed to make getMetaData in @snapwp/next.
  • The same pattern will be followed for the SEO-related meta data too.

@SH4LIN SH4LIN requested a review from justlevine March 19, 2025 13:34
@justlevine
Copy link
Collaborator

@SH4LIN what's with the failing tests?

Also can you add a changeset ?

(Once those are resolved this should be good to merge)

@SH4LIN
Copy link
Collaborator Author

SH4LIN commented Mar 19, 2025

@justlevine Checks are passing now

@SH4LIN SH4LIN requested a review from justlevine March 19, 2025 17:46
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reminder, changesets is "dumb" and major|minor|patch is mapped blindly to x.y.z, not real semver

@justlevine justlevine merged commit f5ef79a into rtCamp:develop Mar 19, 2025
16 checks passed
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.

3 participants