diff --git a/reflex/components/base/script.py b/reflex/components/base/script.py index 3aef867d4..bef2f036b 100644 --- a/reflex/components/base/script.py +++ b/reflex/components/base/script.py @@ -5,6 +5,8 @@ https://nextjs.org/docs/app/api-reference/components/script from __future__ import annotations +from typing import Literal + from reflex.components.component import Component from reflex.event import EventHandler from reflex.vars import Var @@ -27,8 +29,10 @@ class Script(Component): # Required unless inline script is used src: Var[str] - # When the script will execute: afterInteractive | beforeInteractive | lazyOnload - strategy: Var[str] = "afterInteractive" # type: ignore + # When the script will execute: afterInteractive (defer-like behavior) | beforeInteractive | lazyOnload (async-like behavior) + strategy: Var[Literal["afterInteractive", "beforeInteractive", "lazyOnload"]] = ( + Var.create_safe("afterInteractive", _var_is_string=True) + ) # Triggered when the script is loading on_load: EventHandler[lambda: []] diff --git a/reflex/components/base/script.pyi b/reflex/components/base/script.pyi index 9cc95be8c..9ed757cfe 100644 --- a/reflex/components/base/script.pyi +++ b/reflex/components/base/script.pyi @@ -8,6 +8,7 @@ import reflex from reflex.vars import Var, BaseVar, ComputedVar from reflex.event import EventChain, EventHandler, EventSpec from reflex.style import Style +from typing import Literal from reflex.components.component import Component from reflex.event import EventHandler from reflex.vars import Var @@ -19,7 +20,14 @@ class Script(Component): cls, *children, src: Optional[Union[reflex.vars.Var[str], str]] = None, - strategy: Optional[Union[reflex.vars.Var[str], str]] = None, + strategy: Optional[ + Union[ + reflex.vars.Var[ + Literal["afterInteractive", "beforeInteractive", "lazyOnload"] + ], + Literal["afterInteractive", "beforeInteractive", "lazyOnload"], + ] + ] = None, style: Optional[Style] = None, key: Optional[Any] = None, id: Optional[Any] = None, @@ -97,7 +105,7 @@ class Script(Component): Args: *children: The children of the component. src: Required unless inline script is used - strategy: When the script will execute: afterInteractive | beforeInteractive | lazyOnload + strategy: When the script will execute: afterInteractive (defer-like behavior) | beforeInteractive | lazyOnload (async-like behavior) style: The style of the component. key: A unique key for the component. id: The id for the component.