Skip to content

JS template, snippet, scaffold and skill call Delay(), which is never defined #27

Closed

Description

@TMHSDigital

Summary

The JavaScript template, the JS thread-loop snippet, the JS scaffold output and the client-server skill all call await Delay(1000) inside setTick, but nothing defines Delay. The CFX JS runtime has no built-in Delay, so these resources throw ReferenceError: Delay is not defined on every tick.

Where

  • templates/javascript/client/main.js:1-2
  • snippets/javascript/thread-loop.js:2-6
  • mcp-server/tools/scaffold.py:187-191 (_scaffold_js, generated client/main.js)
  • skills/client-server-patterns/SKILL.md:89, skills/client-server-patterns/SKILL.md:168
  • rules/cfx-javascript-conventions.mdc:15

Details

setTick(async () => {
    await Delay(1000);
    // Main client loop
});

git grep "Delay\s*=" finds no definition anywhere in the repo. The FiveM JavaScript docs state that, unlike Lua and C#, there is no built-in Wait or Delay in JS and define their own helper: const Delay = (ms) => new Promise(res => setTimeout(res, ms));. In C#, Delay is a BaseScript method, so the C# templates and snippets are fine.

The JS rule tells agents to "Use setTick with await Delay(ms)", and the snippet comment says "Always await Delay() to yield", both treating it as built in.

Impact

Every resource created with scaffold_resource_tool(language="javascript") or copied from templates/javascript errors on every client tick, spamming the F8 console, and any code after the Delay call never runs. Agents following the rule keep generating the same broken pattern.

Steps to reproduce

  1. Scaffold name=x, game=gta5, language=javascript, framework=standalone, or copy templates/javascript into a server's resources.
  2. ensure the resource and join.
  3. The client console shows ReferenceError: Delay is not defined repeatedly.

Suggested fix

  • Add const Delay = (ms) => new Promise((res) => setTimeout(res, ms)); at the top of templates/javascript/client/main.js, snippets/javascript/thread-loop.js, and the scaffolded client/main.js string in scaffold.py.
  • Update rules/cfx-javascript-conventions.mdc and skills/client-server-patterns/SKILL.md to say the helper must be defined, and show it in the examples.

Acceptance criteria

  • No JS file, scaffold string, or JS example in skills/rules calls Delay without defining it in the same file or snippet.
  • The JS rule and skill mention that Delay is a user-defined helper in JS.
  • A scaffolded JS resource starts with no client console errors.

Getting started

  • Relevant files: templates/javascript/client/main.js, snippets/javascript/thread-loop.js, mcp-server/tools/scaffold.py, skills/client-server-patterns/SKILL.md, rules/cfx-javascript-conventions.mdc
  • How to run checks: there is no test suite yet; run the MCP server with cd mcp-server && pip install -r requirements.txt && python server.py, and CI checks live in .github/workflows/validate.yml
  • Related docs: FiveM JavaScript scripting docs on docs.fivem.net

Filed by repo-audit/full-audit at 701824d. Severity: high. Effort: S. audit-key: bug|templates/javascript/client/main.js|Delay

Activity

  1. added
    bug
    on Nov 21, 2026
  2. TMHSDigital commented on Nov 21, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in fd12569.

    Defined const Delay = (ms) => new Promise(...) in the JS template, the thread-loop snippet and the scaffolded client/main.js, and documented in the JS rule and skills that Delay must be defined.

    Verified: Ran the template, the snippet and a freshly scaffolded client/main.js under node with setTick stubbed: each tick completed without a ReferenceError.

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

    bugseverity: high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions