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

breaking: Refactor global stores for Modal, Toast, and Drawer #1831

Merged
merged 13 commits into from
Aug 9, 2023

Conversation

AdrianGonz97
Copy link
Member

Linked Issue

Closes #522

Description

This PR aims to fix the SSR related issues that comes with stores that are defined in the global scope. To fix this, we'll be using Svelte's context API as a means of attaching these stores to the component tree for safe keeping.

Store Initialization

The first change is how these utility stores are initialized. As we are using contexts now, we need to initialize and set the contexts for these stores in the root layout file.

We provide a utility function, initializeStores(), that will handle the initialization for the users:

<!-- src/routes/+layout.svelte -->
<script lang="ts">
	import { Toast, Modal, Drawer, initializeStores } from "@skeletonlabs/skeleton";
	
	initializeStores();
</script>

<Toast />
<Modal />
<Drawer />

Retrieving Stores

Stores for Modal, Toast, and Drawer are now accessed through a function that will retrieve their respective stores.

import { getToastStore, getDrawerStore, getModalStore } from "@skeletonlabs/skeleton";

const toastStore = getToastStore();
const drawerStore = getDrawerStore();
const modalStore = getModalStore();

...and that's it! It's a pretty minor, yet effective change that clears up all of the nasty SSR issues that these particular stores have been troubling us with.

As a bonus, these stores can now be safely used at the top level of components without any fear of the server's store persisting its state:

<script lang="ts">
	import { toastStore } from '@skeletonlabs/skeleton';

	toastStore.trigger({
		message: 'Howdy!',
		autohide: false
	});
</script>

<!-- ... -->

Changsets

Instructions: Changesets automate our changelog. If you modify files in /packages/skeleton, run pnpm changeset in the root of the monorepo, follow the prompts, then commit the markdown file. Changes that add features should be minor while chores and bugfixes should be patch. Please prefix the changeset message with feat:, bugfix: or chore:.

Checklist

Please read and apply all contribution requirements.

  • This PR targets the dev branch (NEVER master)
  • Documentation reflects all relevant changes
  • Branch is prefixed with: docs/, feat/, chore/, bugfix/
  • Ensure Svelte and Typescript linting is current - run pnpm check
  • Ensure Prettier linting is current - run pnpm format
  • All test cases are passing - run pnpm test
  • Includes a changeset (if relevant; see above)

@changeset-bot
Copy link

changeset-bot bot commented Aug 6, 2023

🦋 Changeset detected

Latest commit: 2eea63b

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

This PR includes changesets to release 1 package
Name Type
@skeletonlabs/skeleton Major

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 Aug 6, 2023

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

Name Status Preview Updated (UTC)
skeleton-docs ✅ Ready (Inspect) Visit Preview Aug 9, 2023 5:54pm

@endigo9740
Copy link
Contributor

Seems good at at glance @AdrianGonz97. I'll test it out this week and we'll aim to get this in for the v2 release. Thank you for updating the docs already as well!

@endigo9740
Copy link
Contributor

@AdrianGonz97 I always like to add context for WHY you're implementing something in the instruction, so I've modified this bit in the featured example for drawers, modals, and toasts:

Screenshot 2023-08-09 at 12 52 02 PM

I think with this I'm good with moving forward and merging this.

@endigo9740 endigo9740 self-requested a review August 9, 2023 17:53
@endigo9740 endigo9740 merged commit 0b7add1 into skeletonlabs:v2 Aug 9, 2023
3 checks passed
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.

None yet

3 participants