derbyjs / racer

Realtime model synchronization engine for Node.js
1.18k stars 116 forks source link

Strip ref outputs from initial data bundle, to reduce size #295

Closed ericyhwang closed 1 year ago

ericyhwang commented 1 year ago

Background

On initial page load, the server model data gets serialized into a data bundle, to be sent to the client in the response HTML.

During this process, stripComputed removes the outputs of ref lists and reactive functions, to reduce bundle size by locally deleting duplicated data that can be easily reconstructed on the client.

As it turns out, normal refs' outputs weren't getting stripped. I presume it wasn't done because, for the current implementation of the cleanup, the deletion of a local ref pointing to a remote (DB-backed) doc would've caused the remote doc to get deleted.

Changes

This PR adds the stripping of ref outputs in the initial data bundle, by using a new internal _delNoDereference that does a purely local delete, not following the ref. That avoids the problem of inadvertently deleting a remote doc during stripComputed.