Skip to content

chore: Adding missing field to store #101

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

amareshsm
Copy link
Member

Prerequisites checklist

What is the purpose of this pull request?

What changes did you make? (Give an overview)

Use the onRehydrateStorage hook to add any new field if it is missing in the store.

The previous implementation - #97, where we checked for missing language code, works fine in cases where a user manually selects a new language from the dropdown. In this scenario, if the corresponding code entry was missing, we could dynamically patch it on the fly.

However, this approach breaks when a user opens a shared link that points directly to a newly added language. Since the state is rehydrated from the URL hash and doesn’t include the new language (because it wasn’t present in the original persisted state), the app can break.

We’re now using the onRehydrateStorage hook provided by Zustand. This hook ensures that immediately after the state is loaded from storage, any missing fields (like code for a new language) are automatically added using defaultCode. This centralises the patching logic inside the store (use-explorer file), ensures the state is always complete, and prevents issues with incomplete or outdated persisted data.

Also, all code logic related to state hydration and defaults stays cleanly inside the Zustand store.

Related Issues

Is there anything you'd like reviewers to focus on?

Copy link

netlify bot commented May 12, 2025

Deploy Preview for eslint-code-explorer ready!

Name Link
🔨 Latest commit 0a80015
🔍 Latest deploy log https://app.netlify.com/sites/eslint-code-explorer/deploys/682275434ed62f00082a16ab
😎 Deploy Preview https://deploy-preview-101--eslint-code-explorer.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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.

1 participant