Skip to content

feat(assignVar): Patch for assignVar to add "drop key" feature and fixes reflecting documentation #350

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

Merged
merged 9 commits into from
May 13, 2025

Conversation

34638a
Copy link
Contributor

@34638a 34638a commented Mar 30, 2025

Proposal, What? Why?

Helper assignVar currently does not have a way to do any of the following features:

  1. Un-Map a assigned value: once a key has been set, it is locked for the whole render pipeline. This results in features like widgets taking up half of the available variables only to use them once and never again, limiting theme developers from being able to add new features due to limited variable space.
  2. Accept an empty string into a variable as its value. Given a string is valid input, all states of a string should be considered as valid, limited by length. For instance, if a variable is set to "" because it is intended to be a placeholder when a value is not provided by the store admins or a customer input, say for a phone number click to call, this will currently cause the store to err.500 instead of handling what should be a valid input. The data input is inherently reasonable, so there is a patch in the validation logic to accept an empty string value instead of rejecting it.
  3. Ingest a SafeString object and treat it like a actual string for purposes of storage and retreival. Current workaround possible as per open issue assignVar helper does not work with SafeString #139

Changes Overview

Create patch for assignVar to add following features:

  • Empty string ( "" ) to be accepted as entry into assignVar helper.
  • Null or Undefined values as input to assignVar now delete the key that was set. This has the use-case of freeing variables assigned by widgets or temporary assignments.
  • Internal conversion via unwrapSafeString call before variable is process to all for storage and retrieval of SafeString contents.
  • Tests for these use-cases in assignVar-getVar.js

How was it tested?

Test cases provided in assignVar-getVar.js file.


cc @bigcommerce/storefront-team

- Empty string ( "" ) to be accepted as entry into assignVar helper.
- Null or Undefined values as input to assignVar now delete the key that was set. This has the usecase of freeing variables assigned by widgets or temporary assignments.
- Tests for these usecases in assignVar-getVar.js
@34638a
Copy link
Contributor Author

34638a commented Mar 30, 2025

Reference to open issue #305

@34638a 34638a changed the title Patch for assignVar to add feature and amend function reflecting documentation / scope. feat(assignVar): Patch for assignVar to add feature and amend function reflecting documentation / scope. Apr 1, 2025
@34638a
Copy link
Contributor Author

34638a commented Apr 11, 2025

Reference to open issue #139
^ This will need to be added as a part of the "string" type checks / validation logic.
Note for @34638a to add this into the next PR push for proposal.

34638a added 3 commits April 11, 2025 14:50
- Patch for 'SafeString' object to be treated as a string instead of as an Object by unwrapping before use.
- Added test cases to reflect 'SafeString' patch use case.
- Patch for 'SafeString' object to be treated as a string instead of as an Object by unwrapping before use.
- Added test cases to reflect 'SafeString' patch use case.
- Move setup commands for constructing global storage outside of assignment logic. Prevents case where a variable does not yet exist and a value is deleted.
@34638a 34638a changed the title feat(assignVar): Patch for assignVar to add feature and amend function reflecting documentation / scope. feat(assignVar): Patch for assignVar to add "drop key" feature and fixes reflecting documentation. Apr 11, 2025
@34638a
Copy link
Contributor Author

34638a commented Apr 11, 2025

Rename title of PR due to 100 character limit:
feat(assignVar): Patch for assignVar to add feature and amend function reflecting documentation / scope. feat(assignVar): Patch for assignVar to add "drop key" feature and fixes reflecting documentation.

@34638a
Copy link
Contributor Author

34638a commented Apr 11, 2025

Amended PR context header to reflect #139 issue.

@34638a
Copy link
Contributor Author

34638a commented Apr 11, 2025

Hey @jairo-bc

Clarification request: given the line comment in the actual code, this reads as incorrect implementation. Can you please confirm if the below code should be interpreted as "the buffer length of 1024 should contain no more than 1024", or as per the current implementation "the buffer cannot hold 1024 character, or more than 1024 characters. The limit is 1023 characters in the buffer."

        // Validate that string is not longer than the max length
        if (utils.isString(value) && value.length >= max_length) {
            throw new ValidationError(`assignVar helper value must be less than ${max_length} characters, 
                but a ${value.length} character value was set to ${key}`);
        }
  • Jordan

…ext gets too large and/or a variable within context gets too large. Bug is that the variable will be replaced with a JS `undefined` when actually being provided to template for rendering. Work around is to use a JS template string to generate the test handlebars with the text to test injected as part of inline.

Added:
- Testing procedure for large text.
@34638a 34638a changed the title feat(assignVar): Patch for assignVar to add "drop key" feature and fixes reflecting documentation. feat(assignVar): Patch for assignVar to add "drop key" feature and fixes reflecting documentation Apr 11, 2025
34638a added 2 commits April 11, 2025 18:03
Add comment to module exports explaining output change.
…rom helper to prevent test, helper mismatch due to magic number change.
@34638a
Copy link
Contributor Author

34638a commented Apr 11, 2025

@jairo-bc @bc-evan-johnson
Other than the above @ for clarification,
I think it's ready for review. Thoughts and feedback are appreciated.

  • Jordan

34638a added 2 commits May 12, 2025 18:03
Edit to also change from "up to limit" to "up to and inclusive of limit" when assigning a new variable in the global storage space.
Line 39 of assignVar.js seems like it does a incorrect check but actually resolves correctly to allow for a limit of 50 variables in practice.
@34638a 34638a requested a review from jairo-bc May 12, 2025 08:21
@jairo-bc jairo-bc merged commit 67d2c54 into bigcommerce:master May 13, 2025
7 checks passed
Copy link
Contributor

🎉 This PR is included in version 6.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants