I use jointjs/rappid where I use the default rectangle to draw elements on my graph.
I can change the text inside the elements by extending the standard.rectangle and changing the attribute:
joint.shapes.standard.Rectangle = joint.shapes.standard.Rectangle.extend({
setText: function (text) {
this.attr('text/text', text);
} });
This works but the element doesn't autoresize to the length of the text.
How can I resize the element (rectangle) so the text fits in it?

A bit late, but maybe someone else will need it. Just add an autosize function:
Add this event handler so autosize will be called on element change:
Check working example: https://resources.jointjs.com/docs/rappid/v3.5/demo/ui/TextEditor/js/inline.js