Thanks to visit codestin.com
Credit goes to github.com

Skip to content

st.code is not displayed correctly if the code block is not in the viewport when the page loads #10231

@Lexachoc

Description

@Lexachoc

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

Please go to https://docs.streamlit.io/develop/api-reference/text/st.code to see the issue.

The code block will display:

Image

as long as the code block is not in the viewport when page reload.

Reproducible Code Example

import streamlit as st

code = '''def hello():
    print("Hello, Streamlit!")'''
st.code(code, language="python")

Steps To Reproduce

  1. Go to https://docs.streamlit.io/develop/api-reference/text/st.code
  2. make sure the code block is not in the current viewport:

Image

  1. Scroll down to see what's going on.
    Image

Expected Behavior

In Chrome, the browser remembers the scroll position, so just reload, and the code block will diplay correctly as it is in the viewport now.

Image

Current Behavior

st.code is not displayed correctly if the code block is not in the viewport when the page loads.

It shows:

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

the copy function is correct.

def hello():
    print("Hello, Streamlit!")

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.41.1
  • Python version:
  • Operating System: Windows 10
  • Browser: Chrome

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:st.codeRelated to the `st.code` elementpriority:P1High priority - fix within two weeksstatus:confirmedBug has been confirmed by the Streamlit teamtype:bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions