Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

tupe12334
Copy link

@tupe12334 tupe12334 commented Aug 29, 2025

Summary

This PR adds a new query-string storage driver that enables storing data directly in URL query parameters. This is particularly useful for creating shareable and bookmarkable application states.

Features

  • Automatic serialization/deserialization: Handles various data types (strings, numbers, booleans, objects, arrays)
  • Browser history integration: Support for pushState/replaceState to control browser navigation
  • SSR compatibility: Works with URL objects in Node.js/SSR environments
  • Configurable base prefix: Avoid query parameter conflicts with other parts of your application
  • URL length warnings: Warns when approaching browser URL length limits
  • Watch functionality: Listen to browser navigation events for reactive updates

Use Cases

  • E-commerce filters that can be shared via URL
  • Dashboard configurations that persist in the URL
  • Server-side rendering with state in query parameters
  • Any application state that benefits from being bookmarkable

Example Usage

import { createStorage } from "unstorage";
import queryStringDriver from "unstorage/drivers/query-string";

const storage = createStorage({
  driver: queryStringDriver({ 
    base: "app",
    updateHistory: true 
  }),
});

// URL: https://example.com/page
await storage.setItem("filter", "active");
// URL becomes: https://example.com/page?app_filter=active

Test plan

  • Unit tests for all driver operations
  • Integration tests with the standard driver test suite
  • Manual testing in browser environment
  • SSR compatibility testing with URL objects

Resolve #668

Add a new storage driver that stores data in URL query parameters, enabling shareable and bookmarkable application state.

Features:
- Automatic serialization/deserialization of various data types
- Browser history integration with pushState/replaceState support
- SSR compatibility with URL object support
- Configurable base prefix to avoid query parameter conflicts
- URL length warning system
- Watch functionality for browser navigation events

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@tupe12334 tupe12334 requested a review from pi0 as a code owner August 29, 2025 14:18
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.

Driver: Add Query String Driver for URL-based Storage
1 participant