Skip to content

Don't show dismissible elements until we are sure of their status #5570

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

Conversation

MitjaBezensek
Copy link
Contributor

@MitjaBezensek MitjaBezensek commented Mar 6, 2025

We used to default to "user didn't dismiss" this yet. Which meant that we always showed a dismissible element first, then we read the actual value, and we then might have dismissed the elements (if that's what the stored state dictated). We now have a "not initialized" state during which we don't show the elements.

Side effect of this change is that some users that have already dismissed these elements might see them again. I guess we could add some sort of migration of the state, but meh, doesn't seem worth the hassle?

Change type

  • improvement

Copy link

linear bot commented Mar 6, 2025

Copy link

vercel bot commented Mar 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
examples ✅ Ready (Inspect) Visit Preview Mar 15, 2025 3:14pm
tldraw-docs ✅ Ready (Inspect) Visit Preview Mar 15, 2025 3:14pm

@huppy-bot huppy-bot bot added the improvement Product improvement label Mar 6, 2025
@MitjaBezensek MitjaBezensek requested a review from mimecuvalo March 6, 2025 16:11
* @public
*/
export function useLocalStorageState<T = any>(key: string, defaultValue: T, initialValue?: T) {
const [state, setState] = useState(initialValue ?? defaultValue)
Copy link
Member

Choose a reason for hiding this comment

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

i think something about overloading the initialized/not-initialized state makes this code hard to reason about. The issue in my head is that it starts with the initialValue but then the developer is supposed to notice that the defaultValue overrides it shortly thereafter in the useLayoutEffect.

i think it feels a little too complex/leaky to the caller for what this hook is doing.

i propose maybe making a separate state: [isInitialized, isNotInitialized]

and then this hook would return:

const [surveyStatus, setSurveyStatus, isInitialized] = useLocalStorageState<SurveyStatus>(
		'devrel-survey',
		'not-dismissed',
	)

or alternatively:

const {surveyStatus, setSurveyStatus, isInitialized}

I think that would help us avoid any of the not-initialized values maybe accidentally getting stored or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, can take a look on how to improve the api of this. It feels like we definitely need to know if we read the value from the storage or not yet. We can't default to just showing the element, since that causes the issue.

Will probably take this up when I'm back from vacation.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. Yeah, I'm just pushing on splitting it out from the enum of possible values so that the state of being loaded/not-loaded isn't tied to what is actually expected in the cookie value.

@steveruizok
Copy link
Collaborator

Swooping on this, great fix, needs to be done. Agree that the API is confusing so I'm going to cut the knot for now since it's internal.

@steveruizok steveruizok added the docs-hotfix-please Trigger a docs hotfix for this PR after merging to main label Mar 15, 2025
@steveruizok steveruizok enabled auto-merge March 15, 2025 14:59
@steveruizok steveruizok added this pull request to the merge queue Mar 15, 2025
Merged via the queue into main with commit 5435d3b Mar 15, 2025
13 of 14 checks passed
@steveruizok steveruizok deleted the mitja/int-978-we-shouldnt-show-dismissable-elements-until-we-are-sure-we branch March 15, 2025 15:10
steveruizok added a commit that referenced this pull request Mar 15, 2025
)

We used to default to "user didn't dismiss" this yet. Which meant that
we always showed a dismissible element first, then we read the actual
value, and we then might have dismissed the elements (if that's what the
stored state dictated). We now have a "not initialized" state during
which we don't show the elements.

Side effect of this change is that some users that have already
dismissed these elements might see them again. I guess we could add some
sort of migration of the state, but meh, doesn't seem worth the hassle?

- [x] `improvement`

---------

Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
@mimecuvalo mimecuvalo mentioned this pull request Mar 17, 2025
5 tasks
github-merge-queue bot pushed a commit that referenced this pull request Mar 17, 2025
followup to #5570
wasn't working on the homepage / make the logic simpler anyway

### Change type

- [ ] `bugfix`
- [ ] `improvement`
- [ ] `feature`
- [ ] `api`
- [x] `other`
huppy-bot bot pushed a commit that referenced this pull request Mar 17, 2025
followup to #5570
wasn't working on the homepage / make the logic simpler anyway

### Change type

- [ ] `bugfix`
- [ ] `improvement`
- [ ] `feature`
- [ ] `api`
- [x] `other`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-hotfix-please Trigger a docs hotfix for this PR after merging to main improvement Product improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants