Skip to content

feat: add default sort order vscode extension setting VSCODE-742#1243

Merged
tculig merged 15 commits intomongodb-js:mainfrom
tculig:VSCODE-742-add-default-sort-order-vscode-extension-setting
Feb 12, 2026
Merged

feat: add default sort order vscode extension setting VSCODE-742#1243
tculig merged 15 commits intomongodb-js:mainfrom
tculig:VSCODE-742-add-default-sort-order-vscode-extension-setting

Conversation

@tculig
Copy link
Contributor

@tculig tculig commented Feb 11, 2026

Description

Ticket: https://jira.mongodb.org/browse/VSCODE-742

Checklist

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@tculig tculig marked this pull request as ready for review February 11, 2026 15:31
@tculig tculig requested a review from a team as a code owner February 11, 2026 15:31
@tculig tculig changed the title feat: Vscode 742 add default sort order vscode extension setting feat: add default sort order vscode extension setting VSCODE-742 Feb 11, 2026
@tculig tculig changed the title feat: add default sort order vscode extension setting VSCODE-742 feat: add default sort order vscode extension setting VSCODE-742 Feb 11, 2026
};

export const getInitialSort = (): SortOption | null => {
if (typeof window !== 'undefined' && window.DEFAULT_SORT_ORDER) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there no better way than putting things on window to be passing default parameters to a redux reducer's slice?

Copy link
Contributor

@lerouxb lerouxb Feb 11, 2026

Choose a reason for hiding this comment

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

Maybe there's a problem here that I can't spot, but surely you can do vscode.workspace.getConfiguration('mdb').get<SortValueKey>('defaultSortOrder') ?? 'default'); and pass it to createStore() as preloadedState?

You only need it by the time you pass store to the provider here https://github.com/tculig/vscode-tiho/blob/9a609299927f7206e967296622a246828786bf03/src/views/app.tsx#L23

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is inside the webview, it shouldn't have access to vscode.workspace, but let me double check..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, it doesn't, can't run vscode.workspace.getConfiguration('mdb').get('defaultSortOrder') inside any of the webview code, including the redux store.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there no standard way to pass information to a webview? How do other extensions pass do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I can research, if you want something to be available at load time, this is the only way. Alternative is to post a massage once the webview loads, but that is gonna be prone to race conditions, flicker, etc. It IS a somewhat established pattern according to ChatGPT, Claude Code and obscure StackOverflow questions: https://stackoverflow.com/questions/58326788/how-to-pass-parameters-into-a-script-in-a-vs-code-webview

Copy link
Contributor

@lerouxb lerouxb Feb 11, 2026

Choose a reason for hiding this comment

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

If there is no better way and this is the best way to do it, can we at least leave a comment where we store things on the window object explaining why. Because I imagine anyone reading the code is going to find it surprising.

As a general rule if we resort to something weird, let's write a detailed comment explaining why.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose we could have also not rendered anything until an initial message with the config arrives (some kind of isLoading state?), but admittedly at this point that's probably more work than it is worth.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in my experience, doing complex things in onLoad, especially for webviews, is fragile AF. The onLoad flag itself is pretty non-reliable

@tculig tculig requested a review from lerouxb February 11, 2026 16:23
@tculig tculig merged commit 8610042 into mongodb-js:main Feb 12, 2026
28 of 29 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