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

Sort keys when encoding tables as JSON #11124

Merged
merged 5 commits into from
Oct 21, 2024

Conversation

winniehell
Copy link
Contributor

@winniehell winniehell commented Oct 20, 2024

Description

Sorts object keys when encoding a table as JSON. This makes JSON objects deterministic which is especially useful for the GLightbox parameters which are part of the rendered HTML. This change may have unintended side effects such as performance degradation which I hope will be revealed by a review.

closes #11122

Checklist

I have (if applicable):

  • filed a contributor agreement.
  • referenced the GitHub issue this PR closes
  • updated the appropriate changelog

@winniehell
Copy link
Contributor Author

winniehell commented Oct 20, 2024

I verified locally that this change resolves #11122 but of course it has larger impact on the code base which I'm not sure is wanted.

@cscheid
Copy link
Collaborator

cscheid commented Oct 21, 2024

Thanks for the PR. The fix makes sense, but json.lua is an upstream dependency, see the header:

--
-- json.lua
--
-- Copyright (c) 2020 rxi
-- https://github.com/rxi/json.lua
--

I have a slight preference towards making a fix upstream first.

@winniehell
Copy link
Contributor Author

@cscheid I can try but that library has not seen any activity in the last four years, so I'm not optimistic it will get merged any time soon.

@cscheid
Copy link
Collaborator

cscheid commented Oct 21, 2024

I'd be more willing to take a PR here if the fix were mergeable upstream first. Your fix creates a dependency between json.lua and Quarto, and that's not really wanted in this context.

@winniehell
Copy link
Contributor Author

yep, I understand. 👍 the alternative however implies that sortedPairs is duplicated upstream which leads to at least two copies in Quarto. There are already multiple anyway so this may not be a big deal.

@cscheid
Copy link
Collaborator

cscheid commented Oct 21, 2024

We're not a go shop but the appropriate proverb applies here: A little copying is better than a little dependency.

@winniehell
Copy link
Contributor Author

We are in agreement here and for this situation and I also dislike big dependency trees. But I have also made bad experience with legacy code bases that had a lot of duplication and some of the duplicates were adjusted to behave slightly different. So there is probably a sweet spot somewhere in the middle (and just to be absolutely clear: I'm not suggesting any change in strategy for Quarto here, just sharing my point of view).

@winniehell
Copy link
Contributor Author

upstream pull request: rxi/json.lua#51

@cscheid
Copy link
Collaborator

cscheid commented Oct 21, 2024

Great! Do you want to amend this PR with those changes? We can take this locally now, and monitor the upstream repo to get the changes when they merge it. Thank you!

@winniehell winniehell force-pushed the sorted-lightbox-parameters branch from 4d70f52 to ba72e1f Compare October 21, 2024 19:20
@winniehell
Copy link
Contributor Author

@cscheid yep, I have also included the other unreleased changes from upstream and created a pull request for your earlier changes: rxi/json.lua#52

@winniehell winniehell force-pushed the sorted-lightbox-parameters branch from ba72e1f to 86ae7b3 Compare October 21, 2024 19:58
Copy link
Collaborator

@cscheid cscheid left a comment

Choose a reason for hiding this comment

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

This looks great, thank you.

We're still missing the changelog update, right?

@cscheid cscheid merged commit a2a22e5 into quarto-dev:main Oct 21, 2024
47 checks passed
@cscheid
Copy link
Collaborator

cscheid commented Oct 21, 2024

Merged - thanks for the PR and followup!

@winniehell winniehell deleted the sorted-lightbox-parameters branch October 21, 2024 20:46
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.

GLightbox options cause HTML output to change
2 participants