Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.tmpl.ts does not reload included parts from import #483

Closed
boeckMt opened this issue Sep 6, 2023 · 2 comments
Closed

.tmpl.ts does not reload included parts from import #483

boeckMt opened this issue Sep 6, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@boeckMt
Copy link

boeckMt commented Sep 6, 2023

Version

Platform

Windows

What steps will reproduce the bug?

When using plain ES modules (.tmpl.ts) as templates, reloading in the browser does not work for imported sub-templates.

e.g.

// default.tmpl.ts

import { PageData } from "lume/core.ts";
import headTmpl from "../_components/head.tmpl.ts";
import bodyTmpl from "../_components/body.tmpl.ts";

export default (data: PageData) => {
  return /*html*/ `<html>
  ${headTmpl(data)}
  <body>
    ${bodyTmpl(data)}
  </body>
</html>`;
};

May related to: #178

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

No response

What do you see instead?

No changes will be shown if anything is changed in a subtemplate.

Additional information

A current workaround might be to define all subtemplates in the same file. However, this prevents reuse in some situations.

e.g.

// default.tmpl.ts
import { PageData } from "lume/core.ts";

const bodyTmpl = (data: PageData) => {
  return /*html*/ `<div>
    ${data.content}
   </div>`;
};

const headTmpl = (data: PageData) => {
  return /*html*/ `<head>
  <title>${data.title}</title>
  ...
</head>`;
};

export default (data: PageData) => {
  return /*html*/ `<html>
  ${headTmpl(data)}
  <body>
    ${bodyTmpl(data)}
  </body>
</html>`;
};
@boeckMt boeckMt added the bug Something isn't working label Sep 6, 2023
@oscarotero
Copy link
Member

This is not a bug, but is how Deno works.
Any module loaded with import ... is cached by Deno and there's no way to refresh the module after any change.

This is why Lume exposes the comp variable:

// default.tmpl.ts

import { PageData } from "lume/core.ts";

export default (data: PageData) => {
  const { comp } = data;

  return /*html*/ `<html>
  ${comp.head(data)}
  <body>
    ${comp.body(data)}
  </body>
</html>`;
};

More info: https://lume.land/docs/core/components/

@boeckMt
Copy link
Author

boeckMt commented Sep 7, 2023

Thanks for the information, at first it did not work because I used the same extension for the components as for the templates.

  • _components/head.tmpl.ts";
  • _components/body.tmpl.ts";

now using

  • _components/head.ts";
  • _components/body.ts";

It works like a charm.

@boeckMt boeckMt closed this as completed Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants