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

feat: upgrade to using runes #126

Merged
merged 10 commits into from
Oct 29, 2024
Merged

feat: upgrade to using runes #126

merged 10 commits into from
Oct 29, 2024

Conversation

paoloricciuti
Copy link
Owner

@paoloricciuti paoloricciuti commented Oct 29, 2024

This is still a WIP because i need to update the docs but i wanted to put it out to get some feedback from the users. I will also need to provide a migration guide.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a pre-release configuration for the sveltekit-search-params package.
    • Added a new GitHub Actions workflow for automated continuous publishing.
    • Enhanced functionality of the sveltekit-search-params package to manage search parameters more effectively, including the introduction of a recursive proxy for dynamic access.
  • Bug Fixes

    • Updated handling of query parameters across various components for improved performance and clarity.
  • Documentation

    • Updated package dependencies to ensure compatibility with the latest features and fixes.
  • Chores

    • Skipped certain tests in the test suite to streamline the testing process.

Copy link

changeset-bot bot commented Oct 29, 2024

🦋 Changeset detected

Latest commit: e795e6c

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

This PR includes changesets to release 1 package
Name Type
sveltekit-search-params 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

Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

Walkthrough

This pull request introduces several significant changes, including the addition of a pre-release configuration file, updates to dependencies, and modifications to Svelte components for improved management of query parameters. A new GitHub Actions workflow is included to automate package publishing. The sveltekit-search-params package is enhanced to utilize "runes," and various existing components are refactored for better reactivity and parameter handling. Additionally, several files are deleted, reflecting a shift in the project's structure and functionality.

Changes

File Change Summary
.changeset/pre.json New file created to define pre-release configuration for sveltekit-search-params package with mode "pre", tag "next", and initial version "3.0.0".
.changeset/yellow-sloths-wave.md Patch introduced for sveltekit-search-params to utilize "runes" for enhanced search parameter management.
.github/workflows/pkg.pr.new.yml New GitHub Actions workflow file created for automated package publishing on push and pull request events.
package.json Updated to include packageManager as "pnpm@9.9.0" and upgraded multiple devDependencies to their latest versions.
playground/package.json Updated devDependencies: @sveltejs/vite-plugin-svelte from ^3.1.1 to ^4.0.0, and svelte from ^4.2.18 to ^5.1.3.
playground/src/routes/+layout.svelte Refactored to replace onMount with a reactive statement using $effect, and updated slot rendering.
playground/src/routes/+page.svelte Deleted file containing a Svelte component for managing query parameters.
playground/src/routes/debounce/+page.svelte Modified to manage multiple query parameters with a new queryParameters function and updated input bindings.
playground/src/routes/default/+page.svelte Consolidated multiple query parameters into a single queryParameters call, simplifying the component.
playground/src/routes/default/obj/+page.svelte Deleted file that managed a query parameter object.
playground/src/routes/default/parameters-obj/+page.svelte Updated to directly reference the obj variable instead of using store syntax.
playground/src/routes/equalityFn/+page.svelte Refactored to use queryParameters with a new structure for state tracking and input bindings.
playground/src/routes/queryparameters/+page.svelte Introduced optimizations for reactivity and updated store access methods.
src/lib/index.ts Updated exports to only include queryParameters from the new sveltekit-search-params.svelte.js.
src/lib/ssp/json-encode.ts Modified return types of encoding/decoding functions to support currying and updated internal logic.
src/lib/ssp/lz-encode.ts Changed return types and parameters in lzEncodeAndDecodeOptions to utilize currying.
src/lib/sveltekit-search-params.svelte.ts New file created for managing URL search parameters with Svelte's reactive stores and navigation API.
src/lib/sveltekit-search-params.ts Deleted file that previously managed URL search parameters.
src/lib/types.ts Introduced CurriedEncodeAndDecode<T> type and updated existing types for encoding/decoding options.
tests/index.test.ts Skipped queryParam test suite and modified several test cases related to query parameters.

Possibly related issues

  • Svelte 5 support #80: This PR addresses the upgrade to utilize "runes" in sveltekit-search-params, which aligns with the changes made in this pull request.

Possibly related PRs

🐰 In the meadow, changes bloom,
A pre-release file dispels the gloom.
With runes to guide our search anew,
Svelte's magic shines bright and true.
Automate the publish, let it flow,
In the garden of code, watch it grow! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Oct 29, 2024

Deploy Preview for sveltekit-search-params ready!

Name Link
🔨 Latest commit e795e6c
🔍 Latest deploy log https://app.netlify.com/sites/sveltekit-search-params/deploys/67216bec00161f00085f9f21
😎 Deploy Preview https://deploy-preview-126--sveltekit-search-params.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

pkg-pr-new bot commented Oct 29, 2024

pnpm add https://pkg.pr.new/sveltekit-search-params@126

commit: e795e6c

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 17

🧹 Outside diff range and nitpick comments (19)
playground/src/routes/default/parameters-obj/+page.svelte (2)

11-12: Consider documenting the migration from store syntax.

The change from $obj.obj to obj.obj reflects the transition from stores to runes. This is a breaking change that should be documented in the pending migration guide.

Would you like me to help draft documentation explaining:

  1. Why the store syntax ($) is no longer needed
  2. How to migrate existing code to the new pattern
  3. Benefits of using runes in this context

Line range hint 1-12: Consider adding type safety for the object structure.

While the code is functional, you might want to enhance type safety for the object structure. This is especially important since runes provide better TypeScript integration.

Consider defining an interface for the object structure:

interface TestObject {
    test: string;
}

const obj = queryParameters({ obj: ssp.object<TestObject>({ test: '' }) });
playground/src/routes/default/+page.svelte (2)

Line range hint 4-14: LGTM! Consider adding type safety.

The consolidation of parameters using queryParameters improves maintainability and readability. The configuration options are properly preserved.

Consider adding explicit type definitions for better type safety:

 const store = queryParameters({
   str2: ssp.string('str2'),
-});
+} as const);
 const store_no_show = queryParameters(
   {
     'str2-no-show': ssp.string('str2-no-show'),
-  },
+  } as const,
   { showDefaults: false },
 );

16-18: Consider consistent parameter access patterns.

While the template bindings work correctly, there's an inconsistency in how parameters are accessed:

  • store.str2 uses dot notation
  • store_no_show['str2-no-show'] uses bracket notation

Consider using bracket notation consistently for better maintainability:

-<span data-testid="str2">{store.str2}</span>
+<span data-testid="str2">{store['str2']}</span>

 <span data-testid="str2-no-show">{store_no_show['str2-no-show']}</span>
src/lib/types.ts (2)

5-7: LGTM! Consider documenting equality function behavior.

The conditional type for equalityFn is well-designed, ensuring type safety by only allowing equality comparisons for object types. This optimization can prevent unnecessary updates when values are semantically equal.

Consider documenting:

  1. The expected behavior of the equality function (deep vs shallow comparison)
  2. Performance implications for large objects
  3. Example implementations for common use cases

10-13: LGTM! Elegant use of TypeScript's type system for currying.

The intersection type elegantly combines the curried function with its base options, enabling a flexible API that supports both direct usage and partial application.

This pattern:

  1. Enables better composition and reusability
  2. Maintains type safety while providing API flexibility
  3. Aligns well with functional programming principles
playground/src/routes/debounce/+page.svelte (1)

Line range hint 4-11: Consider more descriptive parameter names

While the new queryParameters implementation is good, the parameter names could be more descriptive:

  • str2 is misleading as it's a boolean parameter, not a string. Consider a name that reflects its boolean nature.

Consider renaming:

 const params = queryParameters(
   {
-    str2: true,
+    isEnabled: true,
     num: ssp.number(0),
   },
   { debounceHistory: 1000 },
 );
playground/src/routes/equalityFn/+page.svelte (2)

2-2: Document the equality function behavior and consider type improvements.

The equality function () => false might not be immediately clear to other developers. Consider adding a comment explaining why it always returns false and its implications.

Consider making the type more explicit:

-		str: ssp.object<{ value: string }>()(() => false),
+		str: ssp.object<{ value: string }>()(() => false) /* Always treat as changed to force updates */,

Also applies to: 4-7


17-19: Add label for better accessibility.

The input field should have an associated label for better accessibility.

 {#if params.str}
+	<label for="str-input">String Value:</label>
-	<input data-testid="str2-input" bind:value={params.str.value} />
+	<input id="str-input" data-testid="str2-input" bind:value={params.str.value} />
 	<div data-testid="str2">{params.str.value}</div>
 {/if}
.github/workflows/pkg.pr.new.yml (1)

12-16: Consider specifying exact Node.js version.

While using Node.js 20.x is good, for a publishing workflow it's safer to pin to a specific version to ensure consistent builds.

             - run: corepack enable
             - uses: actions/setup-node@v4
               with:
-                  node-version: 20.x
+                  node-version: 20.11.0
                   cache: 'pnpm'
playground/package.json (1)

15-16: Documentation updates needed for playground

Since this is part of a WIP PR that mentions pending documentation, ensure the playground will include:

  1. Examples demonstrating the new runes syntax
  2. Clear indicators that this version requires Svelte 5
  3. Links to the migration guide (once completed)

Consider adding a comment in package.json to indicate the Svelte 5 requirement:

{
  "name": "playground",
  "version": "0.0.1",
  "private": true,
+ "engines": {
+   "node": ">=16.0.0"
+ },
+ "comments": {
+   "svelte": "Using Svelte 5 beta for runes support"
+ },
src/lib/ssp/lz-encode.ts (1)

Line range hint 25-33: Consider adding input validation for decoded JSON.

The current implementation catches JSON parsing errors but doesn't validate the structure of the parsed data. This could lead to runtime type errors if the decoded data doesn't match type T.

Consider adding a type guard or validation function:

function isValidData<T>(data: unknown): data is T {
    // Add validation logic specific to type T
    return true; // Replace with actual validation
}

// Then in the decode function:
try {
    const parsed = JSON.parse(decompressFromEncodedURIComponent(value) ?? '');
    return isValidData<T>(parsed) ? parsed : null;
} catch {
    return null;
}
playground/src/routes/queryparameters/+page.svelte (1)

Documentation needed for runes-based implementation

The CHANGELOG.md shows this is version 3.0.0 with significant changes to the queryParameters functionality, but there's no documentation about the runes-based implementation. Please add:

  1. A dedicated section in the README.md explaining the transition to runes
  2. Code examples showing both the old store syntax ($store) and new direct access patterns
  3. Documentation for the new reactive patterns using $state and $effect
  4. Migration steps for users upgrading from v2.x to v3.x

This will help users understand and adopt the new runes-based implementation smoothly.

🔗 Analysis chain

Line range hint 1-97: Documentation needed for runes migration

Since this is a significant change in the way state is managed (moving to runes), please ensure that the planned documentation and migration guide clearly explain:

  1. The transition from store syntax ($store) to direct store access
  2. The new reactive patterns with $state and $effect
  3. Best practices for handling store updates
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if documentation exists or is being worked on
fd -e md -e mdx . | xargs rg -i "runes|migration|upgrade"

Length of output: 59


Script:

#!/bin/bash
# Let's check for any documentation files in common locations
fd "README|CHANGELOG|MIGRATION|UPGRADE" -e md -e mdx

# Also check package.json for any version changes or migration notes
cat package.json | jq -r '.version, .description'

# Check if there are any docs/documentation directories
fd -t d -d 2 "docs|documentation"

# Look for any inline documentation in the component file itself
rg -i "migration|upgrade|runes" playground/src/routes/queryparameters/+page.svelte

Length of output: 282


Script:

#!/bin/bash
# Let's check the content of CHANGELOG.md and README.md for any migration notes
cat CHANGELOG.md

# Also check the playground README
cat playground/README.md

Length of output: 3203

package.json (1)

44-64: Documentation update needed for dependency changes

Several dependencies have been upgraded to their latest versions. As this PR is marked as WIP and needs documentation updates, please ensure the following in the documentation:

  1. Migration guide for Svelte 5 upgrade
  2. Any breaking changes from major version bumps
  3. Minimum version requirements for all dependencies

Would you like help in generating the documentation for these changes?

tests/index.test.ts (1)

362-362: Consider adding test for multiple default parameters

While the current test is valid, consider adding a test case that verifies multiple default parameters simultaneously to ensure the behavior is consistent across different parameter types.

src/lib/ssp/json-encode.ts (2)

6-14: Avoid defaulting generic type parameters to any for stricter type safety

Currently, the generic type parameters default to any (e.g., T extends object = any). This practice can weaken TypeScript's type checking and may allow unintended types to be used. Consider requiring explicit type parameters or providing more specific defaults to enhance type safety and catch potential bugs at compile time.

Also applies to: 35-43


Line range hint 12-32: Refactor to eliminate code duplication between functions

The implementations of objectEncodeAndDecodeOptions and arrayEncodeAndDecodeOptions are nearly identical, differing primarily in the types they handle. To adhere to the DRY (Don't Repeat Yourself) principle, consider abstracting the shared logic into a single generic function or utility that can handle both objects and arrays. This refactor would improve maintainability and reduce the risk of inconsistencies.

Apply this diff to create a generic function:

+function encodeAndDecodeOptions<T>(
+  defaultValue?: T,
+): CurriedEncodeAndDecode<T> & { defaultValue: T | undefined } {
+  const encode_and_decode = {
+    encode: (value: T) => JSON.stringify(value),
+    decode: (value: string | null): T | null => {
+      if (value === null) return null;
+      try {
+        return JSON.parse(value);
+      } catch {
+        return null;
+      }
+    },
+    defaultValue,
+  };
+  function curry_equality(
+    equality_fn: EncodeAndDecodeOptions<T>['equalityFn'],
+  ) {
+    return { ...encode_and_decode, equalityFn: equality_fn };
+  }
+  return Object.assign(curry_equality, encode_and_decode);
+}
+
-function objectEncodeAndDecodeOptions<T extends object = any>(
-  defaultValue?: T,
-): CurriedEncodeAndDecode<T> {
-  // existing implementation
-}
-
-function arrayEncodeAndDecodeOptions<T = any>(
-  defaultValue?: T[],
-): CurriedEncodeAndDecode<T[]> {
-  // existing implementation
-}

And update any references to use encodeAndDecodeOptions accordingly.

Also applies to: 41-62

src/lib/sveltekit-search-params.svelte.ts (2)

10-10: Correct the grammatical error in the comment.

The comment should read "This allows the application..." instead of "This allow the application..."


68-71: Remove unnecessary commented-out code.

The commented-out Overrides<T> type appears unnecessary. Removing it will improve code clarity and maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bbc9a4a and c6bdbd0.

⛔ Files ignored due to path filters (2)
  • playground/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (20)
  • .changeset/pre.json (1 hunks)
  • .changeset/yellow-sloths-wave.md (1 hunks)
  • .github/workflows/pkg.pr.new.yml (1 hunks)
  • package.json (3 hunks)
  • playground/package.json (1 hunks)
  • playground/src/routes/+layout.svelte (1 hunks)
  • playground/src/routes/+page.svelte (0 hunks)
  • playground/src/routes/debounce/+page.svelte (2 hunks)
  • playground/src/routes/default/+page.svelte (2 hunks)
  • playground/src/routes/default/obj/+page.svelte (0 hunks)
  • playground/src/routes/default/parameters-obj/+page.svelte (2 hunks)
  • playground/src/routes/equalityFn/+page.svelte (1 hunks)
  • playground/src/routes/queryparameters/+page.svelte (2 hunks)
  • src/lib/index.ts (1 hunks)
  • src/lib/ssp/json-encode.ts (3 hunks)
  • src/lib/ssp/lz-encode.ts (2 hunks)
  • src/lib/sveltekit-search-params.svelte.ts (1 hunks)
  • src/lib/sveltekit-search-params.ts (0 hunks)
  • src/lib/types.ts (1 hunks)
  • tests/index.test.ts (5 hunks)
💤 Files with no reviewable changes (3)
  • playground/src/routes/+page.svelte
  • playground/src/routes/default/obj/+page.svelte
  • src/lib/sveltekit-search-params.ts
✅ Files skipped from review due to trivial changes (2)
  • .changeset/pre.json
  • src/lib/index.ts
🔇 Additional comments (23)
playground/src/routes/+layout.svelte (2)

2-2: LGTM! Clean migration to Svelte 5 runes

The script block successfully migrates to Svelte 5 runes syntax. The $effect replacement for onMount is appropriate, and the data attribute initialization is preserved.

Also applies to: 4-5


9-9: LGTM! Proper slot migration pattern

The template correctly migrates from <slot /> to the new runes pattern using {@render children?.()}. The optional chaining operator provides good defensive programming.

playground/src/routes/default/parameters-obj/+page.svelte (2)

1-2: LGTM! Correct runes setup.

The <svelte:options runes /> declaration is correctly placed at the top of the file, which is required for using the new runes syntax.


Line range hint 3-6: Verify the imported functions support runes.

The transition to using queryParameters instead of store-based approach aligns with the runes upgrade. However, we should verify that the imported functions from 'sveltekit-search-params' are designed to work with runes.

✅ Verification successful

The queryParameters function is compatible with runes

The implementation shows full compatibility with runes:

  • Uses $state, $derived, and $effect runes in its implementation
  • The playground examples demonstrate successful usage with <svelte:options runes />
  • The function properly handles reactive state management and updates using the new runes system
  • All example files in the playground successfully use queryParameters with runes enabled

The transition to using queryParameters is appropriate and fully supported in the runes-based architecture.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if queryParameters is properly exported and documented for runes
rg -A 5 "export.*queryParameters" 
rg -A 5 "queryParameters.*runes"

Length of output: 627


Script:

#!/bin/bash
# Let's check the implementation of queryParameters to understand if it's compatible with runes
ast-grep --pattern 'function queryParameters<$_>($_) {
  $$$
}'

# Also check for any runes-related changes or documentation
rg -l "runes" 

Length of output: 224


Script:

#!/bin/bash
# Let's examine the content of these files to understand the runes usage context
cat playground/src/routes/default/+page.svelte playground/src/routes/default/parameters-obj/+page.svelte playground/src/routes/debounce/+page.svelte

# Also check the implementation details of the queryParameters function
cat src/lib/sveltekit-search-params.svelte.ts

Length of output: 10065

src/lib/types.ts (1)

15-15: Verify impact of removing generic type parameter.

The simplification of StoreOptions to remove the generic type parameter makes sense as these options are type-agnostic. However, we should verify this change doesn't break existing code.

✅ Verification successful

Removal of generic type parameter from StoreOptions is safe

The search results confirm that StoreOptions is used consistently throughout the codebase without any generic type parameters. All usages are type-agnostic and only deal with behavioral options like debounceHistory, pushHistory, and sort. The type is primarily used as a parameter in function signatures and is imported/exported without any type parameters, indicating the removal of the generic type is safe and aligns with its actual usage.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any usage of StoreOptions with generic type parameters
# that might break with this change

# Look for StoreOptions<...> pattern in TypeScript files
rg "StoreOptions<" -t ts

# Look for potential type assertions or extensions
ast-grep --pattern 'type $_ = StoreOptions<$_>'

Length of output: 76


Script:

#!/bin/bash
# Let's try a broader search to understand the usage of StoreOptions

# Find all references to StoreOptions
rg "StoreOptions" -A 3 -B 3 -t ts

# Find type declarations that might extend or use StoreOptions
ast-grep --pattern 'type $_ = $$$StoreOptions$$$'

# Find interface declarations that might extend StoreOptions
ast-grep --pattern 'interface $_ extends StoreOptions'

# Find variable declarations using StoreOptions type
ast-grep --pattern 'const $_: StoreOptions = $_'

Length of output: 3946

playground/src/routes/debounce/+page.svelte (4)

1-1: LGTM: Runes configuration properly enabled

The <svelte:options runes /> directive is correctly placed at the top of the file, enabling the new runes syntax as intended by the PR.


14-15: LGTM: Clean input binding and display implementation

The input binding and display implementation are correctly updated to use the new params object while maintaining test IDs.


19-21: LGTM: Clean button handler implementation

The button handler correctly implements the increment operation using the new params object.


Line range hint 3-11: Verify complete migration to runes syntax

Let's verify that all reactive statements in this file are using the new runes syntax and no old-style reactivity remains.

✅ Verification successful

Runes migration is properly implemented

The file is correctly using runes syntax:

  • Has <svelte:options runes /> declaration at the top
  • No old-style reactive statements ($:) are present
  • No store subscriptions using $store syntax
  • All reactivity is handled through the queryParameters API
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for old-style reactive statements ($: or $store syntax)
rg -l '\$:|\$[a-zA-Z]' playground/src/routes/debounce/+page.svelte

Length of output: 68


Script:

#!/bin/bash
# Let's first check the entire content of the file
cat playground/src/routes/debounce/+page.svelte

# Also search for reactive declarations with context
rg -A 2 -B 2 '\$:|\$[a-zA-Z]' playground/src/routes/debounce/+page.svelte

Length of output: 675

playground/src/routes/equalityFn/+page.svelte (2)

9-9: LGTM! Clean state declaration using runes.

The state declaration is clear and follows the new runes syntax.


1-19: Verify runes migration completeness.

Since this is part of the runes upgrade, let's verify that all reactive declarations have been migrated to the new syntax.

✅ Verification successful

The previous search might have been too specific. Let's broaden our search to ensure we catch all potential cases that need migration to runes, including store subscriptions and reactive declarations.


Migration to runes appears complete in this file

The verification shows that all reactive syntax in the file is using the new runes pattern:

  • Using $state() for state management
  • Using $effect() for reactive declarations
  • No old-style $: reactive declarations found
  • Store subscriptions are properly handled with the new syntax
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining old-style reactive declarations in the playground
rg '\$:' playground/src/routes

Length of output: 32


Script:

#!/bin/bash
# Let's search for reactive declarations using ast-grep to ensure we catch all patterns
ast-grep --pattern '$: $_'

# Also search for any $-prefixed variables which might indicate old store syntax
rg '\$[a-zA-Z]' playground/src/routes

# Search for let declarations that might need migration
ast-grep --pattern 'let $_ = $_'

Length of output: 2172

.github/workflows/pkg.pr.new.yml (1)

1-24: Verify the custom publishing tool configuration.

The workflow uses pkg-pr-new which appears to be a custom publishing tool. Since this PR is marked as WIP and involves upgrading to runes, we should ensure this tool is compatible with the new changes.

Let's check for any configuration files or documentation for this tool:

playground/package.json (1)

15-16: Major version upgrades require careful consideration

The upgrade to Svelte 5 (from 4.x) and @sveltejs/vite-plugin-svelte 4.0.0 (from 3.x) represents significant changes:

  • Svelte 5 introduces the new runes API which is currently in beta
  • These changes might introduce breaking changes in the playground

Consider the following recommendations:

  1. Since this is a major version upgrade, ensure all playground examples are updated to demonstrate both traditional and runes-based approaches
  2. Add a note in the playground README about the Svelte 5 beta status
  3. Consider maintaining a separate branch with Svelte 4 compatibility until Svelte 5 is stable
✅ Verification successful

Svelte 5 upgrade is compatible with existing code

The codebase inspection shows that the playground files are already using Svelte 5 runes syntax and features:

  • Files use $state and $effect runes
  • Explicit runes opt-in with <svelte:options runes />
  • Proper usage of untrack from Svelte

The upgrade to Svelte 5 and vite-plugin-svelte 4.0.0 is appropriate as the playground code is specifically designed to demonstrate and test the new runes API.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any Svelte-specific warnings or deprecation notices in the codebase
# that might need attention with the upgrade

# Look for potentially affected Svelte syntax
rg -g '*.svelte' '\$:|\{#each|\{#if|\{#await' -l

# Look for reactive statements that might need migration to runes
ast-grep --pattern 'let $name = $_'

Length of output: 243


Script:

#!/bin/bash
# Let's examine the specific Svelte syntax in the affected files
# and check for patterns that might need updates with Svelte 5

# Check queryparameters page
echo "=== queryparameters/+page.svelte ==="
cat playground/src/routes/queryparameters/+page.svelte

echo -e "\n=== equalityFn/+page.svelte ==="
cat playground/src/routes/equalityFn/+page.svelte

echo -e "\n=== parameters-obj/+page.svelte ==="
cat playground/src/routes/default/parameters-obj/+page.svelte

# Also check if there's any documentation or migration notes
echo -e "\n=== README or documentation ==="
fd -g "README*" -x cat {}

Length of output: 20019

src/lib/ssp/lz-encode.ts (1)

1-4: LGTM! Import changes align with the new curried function pattern.

playground/src/routes/queryparameters/+page.svelte (1)

2-3: LGTM: Import changes align with runes upgrade

The addition of untrack from Svelte is appropriate for optimizing reactivity in the new runes-based implementation.

package.json (3)

8-8: LGTM: Package manager specification added

Adding "packageManager": "pnpm@9.9.0" is a good practice as it:

  • Ensures consistent package management across development environments
  • Aligns with the new GitHub Actions workflow mentioned in the PR summary

Line range hint 69-71: Verify peer dependency compatibility

The peer dependencies have been correctly updated to support Svelte 5:

"peerDependencies": {
    "@sveltejs/kit": "^1.0.0 || ^2.0.0",
    "svelte": "^3.55.0 || ^4.0.0 || ^5.0.0"
}

Let's verify the compatibility:

#!/bin/bash
# Check for any version-specific imports or syntax that might need updates
rg -g '!node_modules' -g '!*.json' 'from ["'\''](svelte|@sveltejs\/kit)' -A 2

56-56: Major architectural change: Upgrade to Svelte 5

The upgrade to Svelte 5 ("svelte": "^5.1.3") introduces significant changes, particularly the new runes system. This aligns with the PR objective but requires careful consideration:

  1. This is a breaking change that will require updates to the codebase
  2. Users will need migration guidance

Let's verify the impact:

tests/index.test.ts (2)

326-326: LGTM: URL parameter ordering assertions are consistent

The modified assertions correctly verify the expected URL parameter ordering behavior.

Also applies to: 344-344, 352-352


460-469: Verify the reduced number of store changes

The test now expects 3 store changes instead of 4, and uses clipboard operations. Please verify:

  1. Why the number of store changes decreased
  2. Document the expected triggers for store changes
  3. Explain why clipboard operations are now required

Let me help verify the changes:

#!/bin/bash
# Search for related store change implementations
rg -A 5 'how-many-store-changes' src/
src/lib/ssp/json-encode.ts (2)

27-32: Verify the use of Object.assign with function objects

Using Object.assign(curry_equality, encode_and_decode) merges the properties of encode_and_decode into the curry_equality function object. While this is a clever approach to combine functionality, it's important to ensure that this pattern behaves as expected and doesn't introduce any unexpected side effects, especially regarding type safety and property enumeration in the resulting object.

Also applies to: 56-61


1-4: LGTM!

The imports are correctly defined, and the necessary types are imported without issues.

src/lib/sveltekit-search-params.svelte.ts (1)

80-81: ⚠️ Potential issue

Verify the import of fromStore from svelte/store.

The fromStore function is imported from svelte/store, but it may not be part of the official Svelte API. Ensure that fromStore is correctly imported or defined.

Run the following script to verify if fromStore is exported:

✅ Verification successful

fromStore is a Svelte 5 API feature

Looking at the package.json, this project is using Svelte 5 ("svelte": "^5.1.3") which introduces the fromStore function as part of its new reactivity system. The import and usage are correct for Svelte 5.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if 'fromStore' is exported from 'svelte/store'

# Test: Search for 'fromStore' in the svelte package. Expectation: 'fromStore' should be defined.
rg 'export.*fromStore' node_modules/svelte

Length of output: 104


Script:

#!/bin/bash
# Let's check the imports in the file and search for fromStore definition
rg "import.*fromStore" -A 2

# Also search for any local definition of fromStore
ast-grep --pattern 'function fromStore'

# Check if fromStore is exported from any local file
rg "export.*fromStore"

# Let's also see the actual import statement in the file
cat src/lib/sveltekit-search-params.svelte.ts

Length of output: 9056


Script:

#!/bin/bash
# Let's check the package.json to see if this is using the latest Svelte version
cat package.json

# Let's also check if there's any local implementation of fromStore
rg -g '!node_modules' -g '!dist' "fromStore" -B 2 -A 2

Length of output: 3750

.changeset/yellow-sloths-wave.md Show resolved Hide resolved
playground/src/routes/default/+page.svelte Show resolved Hide resolved
playground/src/routes/debounce/+page.svelte Show resolved Hide resolved
playground/src/routes/equalityFn/+page.svelte Show resolved Hide resolved
.github/workflows/pkg.pr.new.yml Show resolved Hide resolved
tests/index.test.ts Show resolved Hide resolved
tests/index.test.ts Show resolved Hide resolved
src/lib/sveltekit-search-params.svelte.ts Show resolved Hide resolved
src/lib/sveltekit-search-params.svelte.ts Outdated Show resolved Hide resolved
package.json Outdated
@@ -94,6 +94,6 @@
}
},
"dependencies": {
"@sveltejs/vite-plugin-svelte": "^3.0.2"
"@sveltejs/vite-plugin-svelte": "^4.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

why is vps a dependency here, should be a peerDependency if its really needed, but i thought this was runtime only?

Copy link
Owner Author

Choose a reason for hiding this comment

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

It's definitely a mistake...should've always been in devDeps (possibly in the peers). I don't think i ever touched this so it's probably a byproduct of me generating this lib project a long time ago. Let me move it to devDeps

Copy link
Owner Author

Choose a reason for hiding this comment

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

@dominikg i didn't add @sveltejs/vite-plugin-svelte because it already has a peerdep on kit and svelte...do you think it should also be a peerdep (maybe specifying ^4.0.0?

Copy link
Contributor

Choose a reason for hiding this comment

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

your package does not depend on vps itself, does it? the peer dependency on sveltekit is because it uses its page store but you don't have to repeat a transitive peer dep unless you need it yourself

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
tests/index.test.ts (1)

460-469: Document the expected behavior in equalityFn test

While the test modifications look good, please add comments explaining:

  1. Why clipboard operations are used in this test
  2. What triggers the 3 store changes
  3. How this relates to the equalityFn functionality

Example:

 test('equalityFn impact the amount of rerenders with queryParameters', async ({
   page,
   context,
 }) => {
+  // Using clipboard operations to simulate user input that should trigger store changes:
+  // 1. Initial load
+  // 2. Copy operation
+  // 3. Paste operation
   await context.grantPermissions(['clipboard-read', 'clipboard-write']);
   await page.goto('/equalityFn?str=%7B%22value%22%3A%22test%22%7D');
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c6bdbd0 and 9cc8cb1.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • .github/workflows/pkg.pr.new.yml (1 hunks)
  • package.json (1 hunks)
  • tests/index.test.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/pkg.pr.new.yml
  • package.json
🔇 Additional comments (3)
tests/index.test.ts (3)

4-4: Skipping queryParam test suite requires documentation

The previous review comment about premature test skipping is still valid. Since this PR is upgrading to runes, please ensure the following before skipping tests:

  1. Document the deprecation plan in CHANGELOG.md
  2. Provide migration steps in the planned migration guide
  3. Update documentation to reflect the changes

326-326: LGTM: URL search parameter assertions

The modifications to URL search parameter assertions maintain the same test logic while updating the expected values appropriately.

Also applies to: 344-344, 352-352, 362-362


Line range hint 372-384: Remove redundant skipped test

As noted in the previous review, this test can be safely removed since the same functionality is covered by the queryParameters test below.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
src/lib/sveltekit-search-params.svelte.ts (1)

272-363: Documentation needed for runes implementation.

As mentioned in the PR objectives, documentation updates are needed. Please include:

  1. Migration guide for users moving from the old implementation
  2. Examples of using the new runes-based API
  3. Explanation of the reactive behavior with $state, $derived, and $effect

Would you like help in drafting the documentation and migration guide?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9cc8cb1 and e1c43d3.

📒 Files selected for processing (1)
  • src/lib/sveltekit-search-params.svelte.ts (1 hunks)
🔇 Additional comments (3)
src/lib/sveltekit-search-params.svelte.ts (3)

1-21: LGTM: Clean initialization with proper build-time handling.

The setup properly handles both browser and build environments, with appropriate use of example.com as the default URL.


332-346: Verify effect cleanup.

The pre-effect subscription might need cleanup to prevent memory leaks. Consider whether this effect needs to be cleaned up when parameters are removed or the component is destroyed.

#!/bin/bash
# Search for effect cleanup patterns
rg -A 5 '\$effect\.pre.*\{|\$effect\.root.*\{|\$effect.*cleanup'

89-150: Verify batch update cleanup on navigation interruption.

The batched updates mechanism might leave stale entries if navigation is interrupted or fails. Consider adding cleanup in an error handler and when the component is destroyed.

src/lib/sveltekit-search-params.svelte.ts Outdated Show resolved Hide resolved
@paoloricciuti paoloricciuti merged commit e786ec1 into master Oct 29, 2024
8 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.

2 participants