Skip to content

fix: handle disallowed localStorage, simplify script injection - #167

Open
WarningImHack3r wants to merge 3 commits into
svecosystem:mainfrom
WarningImHack3r:handle-disallowed-ls
Open

fix: handle disallowed localStorage, simplify script injection#167
WarningImHack3r wants to merge 3 commits into
svecosystem:mainfrom
WarningImHack3r:handle-disallowed-ls

Conversation

@WarningImHack3r

Copy link
Copy Markdown

Fixes #166

Inspired by sveltejs/svelte.dev#2081, implementation based on sveltejs/svelte.dev#2082

I also simplified the script injection part in the component: tell me if it's okay both in terms of implementation and PR scope

@changeset-bot

changeset-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dfbec66

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

This PR includes changesets to release 1 package
Name Type
mode-watcher 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

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor
built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
mode-watcher ✅ Ready (View Log) Visit Preview dfbec66

I ALWAYS forget
const rootEl = document.documentElement;
const mode = localStorage.getItem(modeStorageKey) ?? defaultMode;
const theme = localStorage.getItem(themeStorageKey) ?? defaultTheme;
let mode: string = defaultMode;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I didn't use local in this function as I assumed printing a function with toString() would break the import

Also, I don't know about TypeScript types in printed functions, but it looks like JS removes them

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.

localStorage usage in unsupported environments

1 participant