Skip to content

prevent warning: Astro.request.headers is not available in "static" output mode#10196

Merged
lilnasy merged 4 commits intowithastro:mainfrom
lilnasy:headers-warning
Feb 24, 2024
Merged

prevent warning: Astro.request.headers is not available in "static" output mode#10196
lilnasy merged 4 commits intowithastro:mainfrom
lilnasy:headers-warning

Conversation

@lilnasy
Copy link
Copy Markdown
Contributor

@lilnasy lilnasy commented Feb 22, 2024

Changes

  • Makes computing i18n attributes lazy again. Computing preferredLanguage, for example, involves reading the Accept-Language header.

Testing

Existing tests should pass.

Docs

Does not affect usage.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 22, 2024

🦋 Changeset detected

Latest commit: a39335b

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

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Feb 22, 2024
Copy link
Copy Markdown
Member

@Princesseuh Princesseuh left a comment

Choose a reason for hiding this comment

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

Not 100% familiar with the code here, but this looks fine to me!

@github-actions github-actions bot added pkg: vue Related to Vue (scope) pkg: example Related to an example package (scope) pkg: react Related to React (scope) pkg: integration Related to any renderer integration (scope) pkg: create-astro Related to the `create-astro` package (scope) labels Feb 22, 2024
@lilnasy lilnasy changed the base branch from cleanup to main February 22, 2024 17:10
@lilnasy lilnasy removed pkg: vue Related to Vue (scope) pkg: example Related to an example package (scope) pkg: react Related to React (scope) pkg: integration Related to any renderer integration (scope) pkg: create-astro Related to the `create-astro` package (scope) labels Feb 22, 2024
@matthewp
Copy link
Copy Markdown
Contributor

Closes #10212

// TODO: we are making two calls to computeCurrentLocale(). In various cases, one works and the other doesn't.
// Ideally, we could use `renderContext.pathname` which is intended to be the one true "file-system-matchable" path.
// - Arsh
return this.#currentLocale ??= computeCurrentLocale(url.pathname, locales, strategy, defaultLocale) ?? computeCurrentLocale(routeData.route, locales, strategy, defaultLocale);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As mentioned in the previously, we can't use url.pathname because in SSG we get a URL like /en.html, and we won't be able to provide the current locale.

We need to use routeData.pathname if it exists, and routeData.route as a fallback. Also. this code be cleaned up:

return this.#currentLocale = computeCurrentLocale(url.pathname ?? routeData.route, locales, strategy, defaultLocale)

@lilnasy lilnasy merged commit 8fb32f3 into withastro:main Feb 24, 2024
@astrobot-houston astrobot-houston mentioned this pull request Feb 24, 2024
@lilnasy lilnasy deleted the headers-warning branch February 27, 2024 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants