Skip to content

Javascript gets unloaded after remi reloads with "handshake complete" #523

Open
@diovudau

Description

Here is the code for two simple files, "main.py" and "custom.js", living in the same directory.
The purpose is to simulate loading of a 3rd party javascript library. In this example it simply rewrites the innerHTML of a <div> to "Hello World".

However, I cannot get Remi to permanently make it work. What happens is that briefly on load/refresh the javascript is executed and "hello world" appears on the page, but Remi triggers some kind of second loading, indicated with handshake complete in the terminal, which makes "hello world" disappear.

I would expect such a simple, everyday usecase of html and javascript to work.
I am looking forward to comments and explanations.

Here is the code:

main.py

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import os.path
import remi.gui as gui
from remi import start, App

class CustomJavascriptApp(App):
    def __init__(self, *args):
        res_path = os.path.dirname(os.path.abspath(__file__))
        super().__init__(*args, static_file_path={'static': res_path})

    def main(self):
        self.page.children['head'].add_child('customjs', "<script defer src='/static:custom.js'></script>")
        self.containerWidget = gui.VBox()

        self.label = gui.Label("Below this should be the text: 'Hello World'."
        "It will disappear after the page is fully loaded,"
        "with the handshake. Maybe it will show again for a short while after F5 refresh.")

        self.mywidget = gui.Widget( _type="div", width=250, height=200, margin="10px")
        self.mywidget.attributes["id"] = "mywidget"

        self.containerWidget.append(self.label)
        self.containerWidget.append(self.mywidget)

        return self.containerWidget

start(CustomJavascriptApp, address="0.0.0.0", port=2020)

custom.js

   document.getElementById("mywidget").innerHTML = "Hello World";

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions