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

fix(i18n): parse params and props correctly with fallback #12709

Merged
merged 5 commits into from
Dec 12, 2024

Conversation

mtwilliams-code
Copy link
Contributor

Changes

This modifies the logic in getParams and getProps slightly to handle i18n fallback edge cases.

  1. If there are no static path matches in getProps, we return early to avoid an error that occurs in the findPathItemByKey call. This should be a nonbreaking change - I dont see any side effects from these calls and it returns an empty object anyway if there are no static paths. I'm not entirely sure I understand the intended behavior in all scenarios here, so feel free to correct.

  2. In getParams If there are no param matches from route.pattern, we also try the patterns from route.fallbackRoutes so that we correctly parse out the param from the localized URL.

Fixes #12701

Testing

Change to the i18n-routing-fallback fixture to allow testing SSR params and a new test added for Fallback rewrite SSR to validate the param is received correctly. Before this change this test will crash with

12:56:12 [ERROR] TypeError: Missing parameter: id
    at getParameter (file:///Users/mtwilliams/Codebase/astro/packages/astro/test/fixtures/i18n-routing-fallback/dist/i18n-routing-fallback/server/manifest_CSai1Xy5.mjs:24:13)
    ...
    
    500 !== 200
    
        at TestContext.<anonymous> (file:///Users/mtwilliams/Codebase/astro/packages/astro/test/i18n-routing.test.js:2094:10)
        at async Test.run (node:internal/test_runner/test:574:9)
        at async Suite.processPendingSubtests (node:internal/test_runner/test:318:7) {
      generatedMessage: true,
      code: 'ERR_ASSERTION',
      actual: 500,
      expected: 200,
      operator: 'strictEqual'
    }

Docs

This fixes a bug and restores intended behavior, so no docs necessary.

Copy link

changeset-bot bot commented Dec 10, 2024

🦋 Changeset detected

Latest commit: de2584d

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 Dec 10, 2024
Copy link

codspeed-hq bot commented Dec 10, 2024

CodSpeed Performance Report

Merging #12709 will not alter performance

Comparing mtwilliams-code:fix-i18n-params (de2584d) with main (e3bfd93)

Summary

✅ 4 untouched benchmarks

packages/astro/src/core/render/params-and-props.ts Outdated Show resolved Hide resolved
packages/astro/test/i18n-routing.test.js Outdated Show resolved Hide resolved
packages/astro/test/i18n-routing.test.js Outdated Show resolved Hide resolved
@mtwilliams-code
Copy link
Contributor Author

LMK if this is too many tests

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

This was an amazing fix, thank you @mtwilliams-code for that!

.changeset/selfish-paws-play.md Outdated Show resolved Hide resolved
@ematipico ematipico merged commit e3bfd93 into withastro:main Dec 12, 2024
2 checks passed
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.

I18n fallbacks break path params in node adapter
2 participants