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

Add multi-value param bug fix/work around in SDK #1134

Closed
wants to merge 3 commits into from

Conversation

bendvc
Copy link
Collaborator

@bendvc bendvc commented Apr 14, 2023

Description

We are losing multi-value param values in the runtime because of aws-serverless-express as a result of the req.originalUrl not being fully preserved. For example a request for hostname.com/path?param=1&param=2 will eventually be made available in the SDK and down into the PWA-Kit app with only the last param value hostname.com/path?param=2.

Fortunately this issue doesn't happen to effect the req.query property. So as a temporary fix, we'll re-create the location.search value using the req.query paying special attention to the order of the params.

This fix is meant to be ugly so we remove it in the future!

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Changes

  • Patched the location.search property in the react rendering pipeline using the req.params which has the duplicate param values.

How to Test-Drive This PR

  • Goto this url
  • If you see 3 filters applied to the product list, it's working

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

@bendvc bendvc requested a review from a team as a code owner April 14, 2023 23:17
@bendvc bendvc changed the title Add multi-value param bug fix/work around in SDK Add multi-value param bug fix/work around in SDK Apr 14, 2023
@@ -73,6 +73,29 @@ const logAndFormatError = (err) => {
}
}

// Because multi-value params are not supported in `aws-serverless-express` we need to re-add
// the stripped duplicate params.
const FIX_LOCATION_SEARCH = (req, location) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

ALL CAP? 🤨

Copy link
Collaborator

Choose a reason for hiding this comment

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

Lol 😆 same as @alexvuong ... Caps is for constants... I would name it fixMePleaseLocationSearch

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did this intentionally to make it super visible. Doing this will ensure that we remove it once we upgrade the underlying library.

@@ -94,11 +117,15 @@ export const render = async (req, res, next) => {
const WrappedApp = routeComponent(App, false, res.locals)

const [pathname, search] = req.originalUrl.split('?')
const location = {
let location = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are changing property inside the location object, const is still valid

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Artifact of going to different solution iterations. Fixed it.

bfeister
bfeister previously approved these changes Apr 17, 2023
Copy link
Collaborator

@bfeister bfeister left a comment

Choose a reason for hiding this comment

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

Agree with @alexvuong's nits, but not blocking. Thanks for fixing @bendvc! 🙏

wjhsf
wjhsf previously approved these changes Apr 18, 2023
@bendvc bendvc changed the base branch from v3 to develop April 18, 2023 22:15
@bendvc bendvc dismissed wjhsf’s stale review April 18, 2023 22:15

The base branch was changed.

@bendvc bendvc changed the base branch from develop to v3 April 18, 2023 22:15
@bendvc
Copy link
Collaborator Author

bendvc commented Apr 24, 2023

Closing because when v3 is released the new version of serverless-express will be used an should fix this issue. Here is the PR for v2

@bendvc bendvc closed this Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants