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

Issue with Sanity #21

Open
layout-ch opened this issue Apr 30, 2024 · 6 comments
Open

Issue with Sanity #21

layout-ch opened this issue Apr 30, 2024 · 6 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@layout-ch
Copy link

Hi! The integration works like a charm with Astro. Now I'm trying to do the next step which is adding a CMS so that clients can handle their multilanguage website through a Dashboard.

For this I'm trying out Sanity with has a super generous free tier. I did a small repro here with astrolicious-i18n: https://github.com/layout-ch/astro-sanity .

Sanity let you embed your cms on a route of your website, which I did on the /admin route in the astro-config :

export default defineConfig({ site: "https://test.com", output: "hybrid", adapter: vercel(), integrations: [ sanityIntegration( { projectId: "t9cmnozc", dataset: "production", useCdn: false, studioBasePath: "/admin", } ), react(), liciousI18n({ defaultLocale: "fr", locales: ["fr", "de", "en"], strategy: "prefix", sitemap: true, pages: { "a-propos": { de: "ueber-uns", en: "about-us" } } })] });

It works like intended on the dev server but when I deploy to vercel, vercel doesn't seem to like that.

I tried it out without astrolicious-i18n and it works, but once I added the integration to the project, I get a status 500 on the /admin route. Is this because of how astrolicious-i18n handles the routes? Since they are generated automatically on build time, it somehow overrides the /admin route that comes from the sanity integration? Any tips on how to make this work with a headless CMS would be amazing. Thank you in advance !

Side note : everything works when I remove i18n so it is somehow interfering somewhere....

@florian-lefebvre
Copy link
Member

I tried and I think the issue is not caused by the intergration but i a misconfiguration of your astro project. I tried everything to make your project work locally and failed, so i started a brand new following i18n docs then sanity docs. It works perfectly fine https://github.com/florian-lefebvre/astro-i18n-sanity-test

@florian-lefebvre florian-lefebvre closed this as not planned Won't fix, can't repro, duplicate, stale Apr 30, 2024
@layout-ch
Copy link
Author

layout-ch commented Apr 30, 2024

Hi Florian,

I'm reopening this issue as I've managed to identify the cause of the problem. It appears that using <I18NHead /> is causing the conflict with the Sanity integration.

I downloaded your minimal reproduction and added the <I18NHead /> component. Locally, npm run dev works without issues on my Mac. However, deploying to Vercel results in the /admin route becoming inaccessible.

On Vercel you get a status 500 when trying to access the /admin route followed by this error :
20:47:21 [ERROR] TypeError: als.run is not a function at file:///var/task/vercel/path0/.vercel/output/_functions/chunks/_astro-internal_middleware_Cor_ETLZ.mjs:50:14 at applyHandle (file:///var/task/vercel/path0/.vercel/output/_functions/chunks/_astro-internal_middleware_Cor_ETLZ.mjs:17:22) at file:///var/task/vercel/path0/.vercel/output/_functions/chunks/_astro-internal_middleware_Cor_ETLZ.mjs:14:12 at applyHandle (file:///var/task/vercel/path0/.vercel/output/_functions/chunks/_astro-internal_middleware_Cor_ETLZ.mjs:17:22) at file:///var/task/vercel/path0/.vercel/output/_functions/chunks/_astro-internal_middleware_Cor_ETLZ.mjs:19:18 at payload (file:///var/task/vercel/path0/.vercel/output/_functions/entry.mjs:35:25) at applyHandle (file:///var/task/vercel/path0/.vercel/output/_functions/chunks/_astro-internal_middleware_Cor_ETLZ.mjs:17:22) at file:///var/task/vercel/path0/.vercel/output/_functions/chunks/_astro-internal_middleware_Cor_ETLZ.mjs:14:12 at callMiddleware (file:///var/task/vercel/path0/.vercel/output/_functions/entry.mjs:691:27) at RenderContext.render (file:///var/task/vercel/path0/.vercel/output/_functions/entry.mjs:1181:28)

Additionally, attempting to run npm run dev on StackBlitz throws an error: 22:55:09 [ERROR] Cannot read properties of undefined (reading 'data') Stack trace: at getLocales (i18n:astro:149:21)

Here are the links for reference:

My minimal reproduction with : https://github.com/layout-ch/astro-i18n-sanity
StackBlitz example demonstrating the error: https://stackblitz.com/~/github.com/layout-ch/astro-i18n-sanity
It would be great to investigate this further and find a solution to allow using alongside Sanity.
Thanks a lot 🙏🏼

@florian-lefebvre florian-lefebvre added the bug Something isn't working label May 1, 2024
@florian-lefebvre florian-lefebvre changed the title Trying to add a headless CMS to astrolicious i18n Issue with Sanity May 1, 2024
@florian-lefebvre
Copy link
Member

I'm investigating and the issue seems unrelated to sanity. on windows i have no issue with the als but on stackblitz (linux) the als getStore is undefined

@florian-lefebvre
Copy link
Member

florian-lefebvre commented May 1, 2024

https://stackblitz.com/edit/github-ddc8wy?file=src%2Froutes%2Findex.astro this logs undefined but it should be an object. Works locally on windows so maybe an os thing or node version thing? Can someone try it on a linux or a mac to see if it happens as well? Related source code available here:

@florian-lefebvre florian-lefebvre added the help wanted Extra attention is needed label May 1, 2024
@layout-ch
Copy link
Author

on my mac I dont get any errors and that's what I get from the log :

{
  clientOptions: { data: false, translations: false, paths: false },
  translations: {
    initialized: false,
    i18nextConfig: {
      namespaces: [Array],
      defaultNamespace: 'common',
      resources: [Object]
    }
  },
  data: { locale: 'en', locales: [ 'en', 'fr' ], defaultLocale: 'en' },
  paths: {
    pathname: '/',
    routes: [ [Object], [Object] ],
    dynamicParams: {},
    strategy: 'prefixExceptDefault'
  }
}

@florian-lefebvre
Copy link
Member

I didn't update the issue but this error is stackblitz specific, I'll see about vercel tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants