Skip to content

Added settings keys sorting - #533

Open
cub-uanic wants to merge 2 commits into
seanprashad:mainfrom
cub-uanic:master
Open

Added settings keys sorting#533
cub-uanic wants to merge 2 commits into
seanprashad:mainfrom
cub-uanic:master

Conversation

@cub-uanic

Copy link
Copy Markdown

I'm using Git to store my progress in dotfiles and share them between several hosts.
Sometimes, on different hosts, I'm getting the keys in json in a different order.
This makes it difficult to understand exactly what was changed (while in reality, it could be just one line), and also makes diffs larger.
As a solution, I suggest always sort the keys of the settings object.

(the idea is the same as I proposed in philc/vimium#4764)

@seanprashad seanprashad left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hi @cub-uanic! To sync progress across multiple hosts, you can sign in with your GitHub account:

Image

Does this fit your use case? This was meant to replace the export/import functionality

@cub-uanic

Copy link
Copy Markdown
Author

Hi @seanprashad,
Yes, I know about possibility to sign in via GitHub.
However, I'm old-fashioned :) and would like to store and manage my progress locally.

seanprashad

This comment was marked as duplicate.

@seanprashad seanprashad left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Change makes sense - just one small adjustment to ensure exports won't be malformed

Comment on lines +806 to 810
// Serialize the JSON keys in order, so that they're stable across backups
const settings = { completed: [...completed].sort(), starred: [...starred].sort(), notes, solvedDates, reminders };
const keys = Object.keys(settings).sort();
const payload = Object.fromEntries(keys.map((k) => [k, settings[k as keyof typeof settings]])) + "\n";
const blob = new Blob([JSON.stringify(payload, null, 2)], { type: "application/json" });

@seanprashad seanprashad Aug 5, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
// Serialize the JSON keys in order, so that they're stable across backups
const settings = { completed: [...completed].sort(), starred: [...starred].sort(), notes, solvedDates, reminders };
const keys = Object.keys(settings).sort();
const payload = Object.fromEntries(keys.map((k) => [k, settings[k as keyof typeof settings]])) + "\n";
const blob = new Blob([JSON.stringify(payload, null, 2)], { type: "application/json" });
const payload = { completed: [...completed].sort((a, b) => a - b), starred: [...starred].sort((a, b) => a - b), notes, solvedDates, reminders };
const blob = new Blob([JSON.stringify(payload, null, 2) + "\n"], { type: "application/json" });

Right now we're prematurely appending the \n trailing character, which causes JSON.stringify to generate "[object Object]\n" instead of the actual JSON content

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