Skip to content
This repository was archived by the owner on Jun 9, 2022. It is now read-only.
This repository was archived by the owner on Jun 9, 2022. It is now read-only.

Shallow-clone of options object could cause problems #71

@georgecrawford

Description

@georgecrawford

In cdf3d09 I've introduced a (failing, pending) test, which demonstrates how a shallow clone of the options object on Module instantiation might not be enough.

I noticed exactly this case in my app:

  • the options were defined in a JS object
  • a module was instantiated
  • a class was later added, and the module was rendered
  • the module was destroyed
  • a new module, using the same original JS object for config, inherited the additional class

This can so easily cause bugs which are hard to pin down, as it'll depend on a previous sequence of events. In my example, if an alert overlay was given a 'loading' class, all future alert overlays would also get that class.

Options to resolve this include:

  • I ensure the JS object is initialised fresh for every instantiation, or is deep-cloned prior to being used each time
  • FruitMachine does a deep-clone rather than a shallow clone in the constructor (see https://github.com/ftlabs/fruitmachine/blob/master/lib/module/index.js#L45)
  • Each of the non-scalar components of the options object (classes, helpers, template, model, data, children) are shallow-cloned during Module#_configure. This won't help much though, as child elements will still be references.

What do people think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions