fix: DynamicLoading story, Codec and parseXml by mayorovad · Pull Request #125 · maxGraph/maxGraph · GitHub
Skip to content

fix: DynamicLoading story, Codec and parseXml#125

Merged
tbouffard merged 4 commits into
maxGraph:developmentfrom
mayorovad:dynamic-loading-fix
Oct 28, 2022
Merged

fix: DynamicLoading story, Codec and parseXml#125
tbouffard merged 4 commits into
maxGraph:developmentfrom
mayorovad:dynamic-loading-fix

Conversation

@mayorovad

Copy link
Copy Markdown

Summary

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

Problem 1 - parseXml not returning Document


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
Comment thread packages/html/stories/DynamicLoading.stories.js Outdated
@tbouffard

tbouffard commented Oct 22, 2022

Copy link
Copy Markdown
Member

ℹ️ 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>

@tbouffard tbouffard left a comment

Copy link
Copy Markdown
Member

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

tbouffard commented Oct 23, 2022

Copy link
Copy Markdown
Member

@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