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(code-block): fix local-storage breakage #735

Merged
merged 2 commits into from
Oct 3, 2022

Conversation

zchsh
Copy link
Contributor

@zchsh zchsh commented Oct 3, 2022

🎟️ Asana Task
πŸ” Preview Link


Description

This PR fixes an issue where code-block could cause app breakage by trying to access window.localStorage without first confirming that window.localStorage is available.

window.localStorage is not available if the visitor has blocked all cookies.

I've proven out this change in hashicorp/dev-portal#1147.

PR Checklist πŸš€

Items in this checklist may not may not apply to your PR, but please consider each item carefully.

  • Add Asana and Preview links above.
  • Conduct thorough self-review.
  • Add or update tests as appropriate.
  • Conduct reasonable cross browser testing for both compatibility and responsive behavior (We have a Sauce Labs account for this, if you don't have access, just ask!).
  • Conduct reasonable accessibility review (use the WAS as a guide or an axe browser plugin until we establish more formal checks).
  • Identify (in the description above) and document (add Asana tasks on this board) any technical debt that you're aware of, but are not addressing as part of this PR.

@changeset-bot
Copy link

changeset-bot bot commented Oct 3, 2022

πŸ¦‹ Changeset detected

Latest commit: cbfefc0

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

This PR includes changesets to release 1 package
Name Type
@hashicorp/react-code-block Patch

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

@vercel
Copy link

vercel bot commented Oct 3, 2022

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Updated
react-components βœ… Ready (Inspect) Visit Preview Oct 3, 2022 at 2:52PM (UTC)

@zchsh zchsh added the release:canary Triggers a canary release for commits to this pull request label Oct 3, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2022

πŸ“¦ Canary Packages Published

Latest commit: cbfefc0

Published 2 packages

@hashicorp/react-code-block@6.1.1-canary-20221003145352

npm install @hashicorp/react-code-block@canary

@hashicorp/react-intro@0.4.2-canary-20221003145352

npm install @hashicorp/react-intro@canary

return window.localStorage.setItem(key, value)
}

const safeLocalStorage = { getItem, setItem }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this utility function to try to keep the provider code simple, while handling the case where window.localStorage is not available.

@zchsh zchsh marked this pull request as ready for review October 3, 2022 15:01
@zchsh zchsh requested a review from BRKalow October 3, 2022 15:01
@zchsh
Copy link
Contributor Author

zchsh commented Oct 3, 2022

@BRKalow This fix targets the localStorage issue described in 🎟️ App breaks when local storage is disabled. I've tested this pre-release in hashicorp/dev-portal#1147, so I'm fairly confident it's at least on the right track (thanks for the code-block tip in the Asana task!)

Let me know what you think πŸ™‡

@zchsh zchsh merged commit 0aa2389 into main Oct 3, 2022
@zchsh zchsh deleted the zs.fix-code-block-local-storage-breakage branch October 3, 2022 20:35
@hashibot-web hashibot-web mentioned this pull request Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:canary Triggers a canary release for commits to this pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants