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

Multi-site Plugin Support for Canonicals #1671

Open
jdilday opened this issue Nov 21, 2023 · 5 comments
Open

Multi-site Plugin Support for Canonicals #1671

jdilday opened this issue Nov 21, 2023 · 5 comments
Labels
backlog Issue/PR/discussion is reviewed and added to backlog for the further work 🐞 bug

Comments

@jdilday
Copy link

jdilday commented Nov 21, 2023

Describe the Bug

Building canonicals for a SSG head app is usually solved by adding a Vercel env variable or related with the desired host name. In cases where there is a single head app tied to multiple sites in Sitecore this approach does not work.

The multi-site plugin uses the SiteInfoSearchService to grab and store select fields from the Site items from each site in Sitecore and write them to the temp/config.js file. It is not practical to extend this service to include any additional fields from the site item without completely rewriting the service.

To Reproduce

Setting an environment variable on the head app will result in all Sitecore sites that share the same head app to use the same/wrong canonical host name.

The SiteInfoService cannot be extended to include additional fields without rewriting it.

Expected Behavior

The multi-site plugin should write site field values to the temp/config.js file that include those needed for constructing a canonical URL when using SSG.

Possible Fix

Assuming the SiteInfoService was modified to do so, include the ability to get additional fields from the Site items that include values needed to generate the correct canonical meta tags in the single app, multiple site scenario.

Provide environment information

  • Sitecore Version: XM Cloud
  • JSS Version: 21.1.4
  • Browser Name and version: N/A
  • Operating System and version (desktop or mobile): N/A
  • Link to your project (if available): N/A
@art-alexeyenko
Copy link
Contributor

Thank you for reporting this @jdilday.

I'd like to add a little bit of context and our reasoning behind why GraphQLSiteInfoService is the way it is right now. The main thing is we don't want to retrieve more things than we need, thus loading Sitecore and JSS app a little bit less. Retrieving all of the field values could bloat config.js. While it is a kind of a "util" file not meant to be read much, it's best to have it legible.
With that, could you please elaborate more on your scenario, and which fields do you require for it? The service can be extended with just getting the attributes field - and that can contain the extra site stuff.

@jdilday
Copy link
Author

jdilday commented Dec 6, 2023

Hi @art-alexeyenko

I agree with your point about not wanting to pull all of the possible data in the SiteInfoService, that makes total sense. The challenge we are solving involves the multi-site scenario where we have one head app serving multiple sites. Neither the multi-site plugin nor the SiteInfoService offer a way to get the canonical URL for the head section of a page when using SSG.

In our scenario, the host name can't be pulled from the route as that can't be known at compile time. We also can't set the hostname as a Vercel variable because, again, it's only one head app serving several sites with different hostnames.

We solved the issue by creating a custom plugin that retrieves the 'Other Properties' field using a method similar to the SiteInfoService. We store the canonical hostname for each site in that field.

We tried to extend the SiteInfoService, but that would require extending/overriding most of the types, functions, and the GraphQL query so we felt it was better create our own custom plugin.

Can you please elaborate on "just getting the attributes field"?

@art-alexeyenko
Copy link
Contributor

@jdilday "Other properties" field is actually what I meant as "attributes field" :)
Let me register an item in our backlog to retrieve that field from Sitecore in our SiteInfo service and make it available for usage. Your usecase is probably not the only one that can be addressed with that change.

@jdilday
Copy link
Author

jdilday commented Dec 7, 2023

@art-alexeyenko - great to hear! Thanks for adding this to your backlog. We will continue using our custom plugin, but replace it with your updates whenever they're ready.

@jdilday
Copy link
Author

jdilday commented Dec 13, 2023

@art-alexeyenko - FYI - the favicon also has the same issue as canonical when using multi-site. Using above mentioned solution. No action expected, informational post only.

@art-alexeyenko art-alexeyenko added the backlog Issue/PR/discussion is reviewed and added to backlog for the further work label Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Issue/PR/discussion is reviewed and added to backlog for the further work 🐞 bug
Projects
None yet
Development

No branches or pull requests

2 participants