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

[Bug]: FabricObject.prototype.set does not take effect #10031

Open
7 tasks done
Yi-Wo-Zuo opened this issue Jul 31, 2024 · 6 comments
Open
7 tasks done

[Bug]: FabricObject.prototype.set does not take effect #10031

Yi-Wo-Zuo opened this issue Jul 31, 2024 · 6 comments

Comments

@Yi-Wo-Zuo
Copy link

CheckList

  • I agree to follow this project's Code of Conduct
  • I have read and followed the Contributing Guide
  • I have read and followed the Issue Tracker Guide
  • I have searched and referenced existing issues and discussions
  • I am filing a BUG report.
  • I have managed to reproduce the bug after upgrading to the latest version
  • I have created an accurate and minimal reproduction

Version

6.0.2

In What environments are you experiencing the problem?

No response

Node Version (if applicable)

None

Link To Reproduction

none

Steps To Reproduce

  1. npm install fabric
  2. import { FabricObject } from "fabric";
  3. FabricObject.prototype.set({
    cornerStrokeColor: "#000000",
    cornerColor: "#000000",
    cornerStyle: "square",
    transparentCorners: false,
    cornerSize: 6, //边角大小
    borderScaleFactor: 1,
    borderColor: "#000000",
    borderDashArray: [6],
    padding: 5,
    });

Expected Behavior

import { FabricObject } from "fabric";

FabricObject.prototype.set({
cornerStrokeColor: "#000000",
cornerColor: "#000000",
cornerStyle: "square",
transparentCorners: false,
cornerSize: 6, //边角大小
borderScaleFactor: 1,
borderColor: "#000000",
borderDashArray: [6],
padding: 5,
});

Actual Behavior

import { FabricObject } from "fabric";

FabricObject.prototype.set({
cornerStrokeColor: "#000000",
cornerColor: "#000000",
cornerStyle: "square",
transparentCorners: false,
cornerSize: 6, //边角大小
borderScaleFactor: 1,
borderColor: "#000000",
borderDashArray: [6],
padding: 5,
});

Error Message & Stack Trace

No response

@zhe-he
Copy link
Contributor

zhe-he commented Jul 31, 2024

Hmm... Do you want to set a default value? Or intercept the set? Use method a for setting a default value and method b for intercepting.

import { FabricObject } from "fabric";
// a
FabricObject.ownDefaults.borderColor = "#000000"

// b
const lastSet = FabricObject.prototype.set;
FabricObject.prototype.set = function(k, v) {
    console.log("before set", k, v);

    const r = lastSet.call(this, k, v);

    console.log("after set", k, v);

    return r;
}

@asturur
Copy link
Member

asturur commented Jul 31, 2024

You can't use the method set directly from the prototype in that way, you are calling it without context it doesn't have a THIS that make sense.

@folknor
Copy link

folknor commented Aug 7, 2024

Is it impossible to set custom props now? I was unsure if this was related to this issue or not.

I have for example

loadSVGFromURL(icon.svg, (_, svg) => {
	var size = util.getRandomInt(24, 48)
	svg.scaleToWidth(size)
	svg.set({
		left: util.getRandomInt(size / 2, maxWidth - size),
		top: util.getRandomInt(size / 2, maxHeight - size),
		id: icon.id,
		origSize: size,
		lockRotation: true,
		lockScalingX: true,
		lockScalingY: true,
		hasControls: false
	})
	svg.setCoords()
	canvas.add(svg)
})

But id: icon.id, this property is at least not serialized when I do for example canvas.toObject(["id", "origSize", "centered"])

This worked in 5.x.x before

@asturur
Copy link
Member

asturur commented Aug 7, 2024

it should be serialized, if it doesn't is a bug.
Can you make a reproducible example?

@folknor
Copy link

folknor commented Aug 8, 2024

When I made a reduced test case it worked fine lol

So no bug, my fault gg

@asturur
Copy link
Member

asturur commented Aug 8, 2024

Yeah that is usually the outcome. When you focus on reproducing in an isolated case you fix it.

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

No branches or pull requests

4 participants