Skip to content

TypeScript live reload doesn't work with js.Build when loaded with .Page.Resources #10726

Open
@sppmacd

Description

@sppmacd

When you change a js.Build-ed file, it is not live reloaded; you need to restart the server for the changes to be applied. This seems to be because of caching in resources/transform.go - if you remove line 371 from that file, everything works.

This is not reproducible with plain JS files.

Reproduce

  • create a new site (hugo new site repro)
  • add a shortcode js.html:
{{ $path := .Get 0 }}
{{ $js := .Page.Resources.GetMatch $path | js.Build (dict "minify" true "targetPath" (printf "%s.js" (path.BaseName $path))) }}
<script src="{{ $js.RelPermalink }}" defer></script>
  • create content/_index.md:
---
date: 2023-02-15T18:04:00+01:00
---

{{< js "test.ts" >}}
  • create content/test.ts with some TypeScript
  • start a server hugo server
  • change the TypeScript file in some way, change will be detected (and page reloaded) but new code is not used until restart.

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.111.0-DEV-9af78d11003ed22b6281e47e1ac19568cf1cca81 linux/amd64 BuildDate=2023-02-08T09:22:20Z

Does this issue reproduce with the latest release?

Yes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions