Skip to content

Update Script Tag Behavior #628

Closed
Closed
@Archmonger

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

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