Skip to content

Conversation

@mayorovad
Copy link

Summary

So I tried to fix DynamicLoading story and stumbled across multiple problems.

Problem 1 - parseXml not returning Document

export const parseXml = (xmlString: string): HTMLElement => {
return new DOMParser().parseFromString(xmlString, 'text/xml').documentElement;
};

Don't know why it's added, but original code of parseXml returning Document and not HTMLElement, which is breaking compatibility. In most cases parseXml result is used at Codec constructor, which needs Document.
Removed .documentElement.

Problem 2 - Codec.decode trying to get constructors from window

try {
// @ts-ignore
ctor = window[node.nodeName];
} catch (err) {
// ignore
}

It can work with vanilla JS imports, but bundlers (webpack) will kill this code very easy.
Added method getCodecByName for getting constructor from CodecRegistry directly by name, It's seems to work, don't really know about side-effects of this change, need advice.

Problem 3 - graph.container.clientWidth and graph.container.clientHeight is always 0 in Storybook

I don't understand why it's like that (maybe some CSS trickery), replaced it with args.width and args.height.

Description for the changelog

Fix DynamicLoading story
Restored backward compatibility when using parseXml
Possible fix for Codec.decode method issue

Other info

DynamicLoading is fixed, but until #115 fix is merged, cells will not remove and story will look very strange 😸

@tbouffard tbouffard added the bug Something isn't working label Oct 9, 2022
@tbouffard
Copy link
Member

tbouffard commented Oct 22, 2022

ℹ️ in the original mxGraph code, the getCodec function could take a string parameter.

We still have some remaining part after migration to TypeScript in Codec.decodeCell. So this method probably fails.
For the record, CodecRegistry structure is directly derived from typed-mxgraph: https://github.com/typed-mxgraph/typed-mxgraph/blob/v1.0.7/lib/io/mxCodecRegistry.d.ts

I guess we could make getCodec takes a string parameter, and benefits from alias (as I mentioned in #102), but if the proposed implementation works with getCodecByName works, let's go for it.

I will test the proposed implementation soon.

Co-authored-by: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com>
Copy link
Member

@tbouffard tbouffard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix 💪🏿.
The cells now display and new elements are added on click. As mentioned in the PR description, this story will be fully fixed when the cell deletion will work (#115)

dynamic-loading-fix-demo.mp4

@tbouffard
Copy link
Member

tbouffard commented Oct 23, 2022

ℹ️ about the graph.container properties always set to 0, someone propose the same fix in the past: 62226e8 (#88)

This commit also proposed a fix for a typo that I have ported here: 386d09f 'fix typo when calling style.perimeter'

@tbouffard tbouffard merged commit 9428ba2 into maxGraph:development Oct 28, 2022
@mayorovad mayorovad deleted the dynamic-loading-fix branch October 29, 2022 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants