Skip to content

Props are not passed down to Path constructor #2012

@HriBB

Description

@HriBB

This is bug report - a continuation of #1988.

Description/Steps to reproduce

It's hard to reproduce, so I will try to explain.

Problem is the createPath function in src/path/Path.Constructors.js

function createPath(segments, closed, args) {
    var props = Base.getNamed(args),
        path = new Path(props && ( // <---- THIS SHOULD BE new Path(props)
            props.insert == true ? Item.INSERT
            : props.insert == false ? Item.NO_INSERT
            : null
        ));
    path._add(segments);
    // No need to use setter for _closed since _add() called _changed().
    path._closed = closed;
    // Set named arguments at the end, since some depend on geometry to be
    // defined (e.g. #clockwise)
    return path.set(props, Item.INSERT);
}

I am hitting this because I have insertItems set to false in my PaperScope.settings. Then I am applying project in my renderer

createInstance: (type: Type, instanceProps: Props, scope: Container) => {
  const props: Props = { ...instanceProps, project: scope.project }

  let instance: Instance

  switch (type) {
    case Item.View:
      instance = scope.view
      instance.project = scope.project
      break
    case Item.Layer:
      instance = new scope.Layer(props)
      break
    case Item.Group:
      instance = new scope.Group(props)
      break
    case Item.Path:
      instance = new scope.Path(props)
      break
    case Item.Circle:
      instance = new scope.Path.Circle(props)
      break

But props are never passed down to Item._initialize and my code throws an Error.

Link to reproduction test-case

Unfortunately I don't have a reproduction test case available ATM, but I can make a PR ;)

Expected result

props are correctly passed down.

Additional information

PaperJS version 0.12.15

1

2

As you can see in the image below, both props and project are null.

3

Metadata

Metadata

Assignees

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