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(gatsby-link): trailing slash undefined check for prod env #34765

Merged
merged 1 commit into from
Feb 8, 2022

Conversation

imjoshin
Copy link
Contributor

@imjoshin imjoshin commented Feb 8, 2022

Description

We weren't checking for __TRAILING_SLASH__ not being set in prod environments. I wanted to add a test for this as well, but looks like we do similar checks elsewhere so we can't utest this in a simulated prod environment.

If anyone looks at this in the future, here's the test we could add:

['development', 'production'].forEach(nodeEnv => {
  it(`handles option not set in ${nodeEnv} (legacy behavior)`, () => {
    process.env.NODE_ENV = nodeEnv
    delete global.__TRAILING_SLASH__
    expect(rewriteLinkPath(`/path`, `/`)).toBe(`/path`)
    expect(rewriteLinkPath(`/path/`, `/`)).toBe(`/path/`)
    expect(rewriteLinkPath(`/path#hash`, `/`)).toBe(`/path#hash`)
    expect(rewriteLinkPath(`/path?query_param=hello`, `/`)).toBe(
      `/path?query_param=hello`
    )
    expect(rewriteLinkPath(`/path?query_param=hello#anchor`, `/`)).toBe(
      `/path?query_param=hello#anchor`
    )
  })
})

Note: I did run this test to duplicate the error. Then, I added the fix and saw a different error than the __TRAILING_SLASH__ is not defined error, and that fell into a similar check later on in the trailing slash flow. (checking for __BASE_PATH__ in https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-link/src/index.js#L33).

Related Issues

[sc-45955]

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Feb 8, 2022
Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

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

Thank you!

@pieh pieh added topic: frontend Relates to frontend issues (e.g. reach/router, gatsby-link, page-loading, asset-loading, navigation) and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Feb 8, 2022
@pieh pieh changed the title Fix trailing slash undefined check for prod env fix(gatsby-link): trailing slash undefined check for prod env Feb 8, 2022
@pieh pieh merged commit d3f2f5e into master Feb 8, 2022
@pieh pieh deleted the hotfix/trailing-slash-prod branch February 8, 2022 19:31
@pieh pieh added this to To cherry-pick in V4 Release hotfixes via automation Feb 8, 2022
imjoshin added a commit that referenced this pull request Feb 8, 2022
@imjoshin imjoshin moved this from To cherry-pick to Backport PR opened in V4 Release hotfixes Feb 8, 2022
imjoshin added a commit that referenced this pull request Feb 8, 2022
#34766)

(cherry picked from commit d3f2f5e)

Co-authored-by: Josh Johnson <jcjohnson77@gmail.com>
@imjoshin imjoshin moved this from Backport PR opened to Backported in V4 Release hotfixes Feb 8, 2022
@imjoshin
Copy link
Contributor Author

imjoshin commented Feb 8, 2022

Published in gatsby-link@4.7.1

@imjoshin imjoshin moved this from Backported to Published in V4 Release hotfixes Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: frontend Relates to frontend issues (e.g. reach/router, gatsby-link, page-loading, asset-loading, navigation)
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants