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

Upgrade sortablejs #15333

Merged
merged 7 commits into from
May 21, 2024
Merged

Upgrade sortablejs #15333

merged 7 commits into from
May 21, 2024

Conversation

fitztrev
Copy link
Member

sortablejs is used for drag+drop reordering of study chapters

  • upgrade from 1.4.2 to 1.15.2
  • refactor to load with esm

@fitztrev fitztrev requested a review from schlawg May 19, 2024 12:14
Copy link
Collaborator

@schlawg schlawg left a comment

Choose a reason for hiding this comment

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

Better to import Sortable directly in the code that uses it. Code splitting will do the rest.

@fitztrev
Copy link
Member Author

Thanks for taking a look. I just tried that to see what happens. It would download sortable.js for anyone who visits a study page.

Right now the loadEsm() call is in a conditional for only people that have permission to re-order the chapters.

Can change it if the other is preferred.

@ornicar
Copy link
Collaborator

ornicar commented May 20, 2024

It's important IMO that the dependency is only downloaded by people who can actually use it. Most study pages are loaded for viewer, not contributors. That includes broadcasts.

@schlawg
Copy link
Collaborator

schlawg commented May 20, 2024

Ok. I wanted to see if esbuild could just bundle a tiny slice of this module but apparently it's a monolith class anyway so we get the whole thing.

Let's at least get rid of the shim analyse/plugins/sortable.ts as sortablejs is already esm. It can be brought in conditionally using a plain dynamic import statement i.e. import(site.asset.url(...)).then(s => s.Sortable.whatever);

But for those who prefer eating our own dogfood, I went ahead and added an npm flag to loadEsm, which resolves to the assets/npm folder rather than assets/compiled as a base. When the init parameter is false, it's equivalent to a plain dynamic import statement like the one above.

There is also some unrelated, harmless refactoring of some names. But it should be uncontroversial. I hope you don't mind i pushed directly to your repo.

@ornicar ornicar merged commit edd73b2 into lichess-org:master May 21, 2024
3 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.

None yet

3 participants