Skip to content

Update Script Tag Behavior #628

Closed
Closed

Description

@Archmonger

Current Situation

Currently the script tag always expects scripts to be structured as a effect hook...

// this is run on every render
() => {
  // this is run once the script is loaded and each time its content changes
  return () => {
    // this is run when the script is unloaded (i.e. it's removed from the tree) or just before its content changes
  }
}

Proposed Actions

The script tag should behave as a normal script by default

Utilize one of the following designs

  1. A parameter to utilize a destructor.
    • It could possibly be a kwarg called destructor="...", which is the name of a JavaScript function within this script's scope that will be called on unload
    • Alternatively, could be a boolean flag such as returns_destructor to denote the script is a singleton function with a destructor
  2. Instead of assuming the script is like an effect, we should be able to check if the script evals to a function, and if it does, we'll call it like an effect

Work Items

  • Develop a method to create normal scripts
  • Consider adding support for a src=... tag, if it does not exist

Activity

  1. added this to the 1.0 milestone on Jan 29, 2022
  2. Archmonger commented on Feb 2, 2022

    @Archmonger
    ContributorAuthor

    @rmorshea Was this resolved in #632 ?

  3. rmorshea commented on Feb 2, 2022

    @rmorshea
    Collaborator

    Yup. Good catch.

  4. Archmonger commented on Feb 3, 2022

    @Archmonger
    ContributorAuthor

    Confirmed that it works great for my sign out (window.location.reload) button scenario!

    Archmonger/Conreq@28f4883

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority-2-moderateShould be resolved on a reasonable timeline.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions