inertiajs / inertia

Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
https://inertiajs.com
MIT License
6.3k stars 423 forks source link

feat: tiny alternatives for `lodash.isequal` and `lodash.clonedeep` -> `just` #1791

Closed SergkeiM closed 7 months ago

SergkeiM commented 7 months ago

Hi @reinink

The purpose of this PR is to reduce the size of inertiajs.

If we check the size of @inertiajs/inertia-vue3

75% - belongs to lodash.isequal (3.8kB min + gzip) and lodash.clonedeep (3.3kB min + gzip)

image

In this PR:

lodash.isequal is replaced by just-compare (419B min + gzip) lodash.clonedeep is replaced by just-clone (410B min + gzip)

Note: I have a custom build of inertia/vue3 with these 2 libraries and didn't had any issues so far.

Differences with Lodash: lodash.clonedeep - Lodash can merge circular references, just-clone only merges plain objects, regular arrays, functions and primitives Lodash merges additional non-plain object types, Lodash treats sparse arrays as dense

SergkeiM commented 7 months ago

@jessarcher @claudiodekker FYI

jamesh-purr commented 7 months ago

@jessarcher @reinink When do we think this could be looked at and potentially merged? I need this issue resolved asap and if this does indeed resolve the issue without any problems then I am +1 on getting this merge asap.

reinink commented 7 months ago

Hey! As noted in #1792 as well, thanks for this suggestion, but I think we're going to stick with lodash for now because this is just too risky of a change as there could be unexpected side effects for not a lot of gain. Might revisit this in the future, but for now going to leave it as is 👍

RomainLanz commented 7 months ago

Hey @reinink! 👋🏻

To avoid any unexpected side effects, you could release a beta version with those changes and see if anyone come with an issue. Since it is an easy change, it is also easily revertable.

Looking at the source code and test suite, it seems to be 100% compatible. Also, looking at the usage of lodash.isequal, the native structuredClone function may be enougth.

SergkeiM commented 7 months ago

Hi @RomainLanz, @reinink

Agree, having lodash.isequal and lodash.clonedeep removed, saves 7.1kB min + gzip combined, this is more then 50% of vue 3 size (13.5kb)