stackblitz / tutorialkit

TutorialKit by StackBlitz - Create interactive tutorials powered by the WebContainer API
https://tutorialkit.dev
MIT License
503 stars 48 forks source link

feat: access current lesson from Astro.locals #398

Open eric-burel opened 3 weeks ago

eric-burel commented 3 weeks ago

This PR introduces a way to access the current lesson frontmatter / collection entry from any component, using Astro.locals as a server context.

I've tried to find simpler alternatives:

I needed to pass an additional entrySlug to be able to call getEntry later on. I focused on lessons at the moment.

Use cases would be crafting reusable lesson-specific component, that are able to figure the lesson URL, reuse the frontmatter config etc. For instance I am trying to wrap up a "Share on Bluesky" component.

stackblitz[bot] commented 3 weeks ago

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

eric-burel commented 2 weeks ago

Alright ! So the TutorialStore is a stateful singleton as far as I can tell from the code.

However I see setLesson being called only in WorkspacePanelWrapper in a useEffect hook: is this value available in server-side Astro components as well? I feel like it only works in islands, and is strongly tied to the WorkspacePanel component loading first.