Skip to content

Re-attaching Markdown component makes the content dissappear #7805

@mstahv

Description

@mstahv

Description

Re-attaching a Markdown component back to the component tree makes the content dissappear (only tag is in the DOM).

Expected outcome

Should work.

Minimal reproducible example

        var md = new Markdown("""
                # Markdown testing
                
                Markdown paragraph.
                """){
            /*
            // The official workaround :-) 
            @Override
            protected void onDetach(DetachEvent event) {
                try {
                    Field clientContent = Markdown.class.getDeclaredField("clientContent");
                    clientContent.setAccessible(true);
                    clientContent.set(this, null); // reset the client content to force re-rendering
                    Method scheduleContentUpdate = Markdown.class.getDeclaredMethod("scheduleContentUpdate");
                    scheduleContentUpdate.setAccessible(true);
                    scheduleContentUpdate.invoke(this);
                } catch (NoSuchMethodException e) {
                    throw new RuntimeException(e);
                } catch (InvocationTargetException e) {
                    throw new RuntimeException(e);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException(e);
                } catch (NoSuchFieldException e) {
                    throw new RuntimeException(e);
                }
            }
             */
        };

        add(new Button("Toggle markdown attachment", e -> {
            // Detach and re-attach the Markdown component to test if it works correctly
            if(md.isAttached()) {
                remove(md);
            } else {
                // Only empty element will appear in the UI
                add(md);
            }
        }));

        add(md);

Steps to reproduce

Click the button in the example code.

Environment

Vaadin version(s): latest
OS: mac

Browsers

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions