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

async assigning a value to metatags doesn't work #279

Closed
Kneemund opened this issue Oct 2, 2020 · 12 comments
Closed

async assigning a value to metatags doesn't work #279

Kneemund opened this issue Oct 2, 2020 · 12 comments
Assignees

Comments

@Kneemund
Copy link

Kneemund commented Oct 2, 2020

Bug Description
Assigning a value to metatags inside of a function (e.g. a request callback) throws Error: Function called outside component initialization.

Routify Version
2.1.3 (latest)

Example

import { ready, metatags } from '@roxi/routify';
[...]

$: user = {};

axios.post([...]).then((res) => {
        user = res.data;
        metatags.title = "test";
        $ready();
});
@jakobrosenberg jakobrosenberg changed the title assigning a value to metatags inside of a function throws an error async assigning a value to metatags doesn't work Oct 2, 2020
@jakobrosenberg jakobrosenberg self-assigned this Oct 2, 2020
@madeleineostoja
Copy link

I also hit this issue, fairly large use case with metadata coming from a CMS (for example).

@ghostdevv
Copy link
Member

Is this still an issue @jakobrosenberg

@jakobrosenberg
Copy link
Member

AFAIK yes.

@lamualfa
Copy link

@jakobrosenberg

Please give a warning to metatags section. for 2 days I tried to find the cause of this error. First time, I thought this error came from Vite. it turns out that the error comes from the metatags helper 😂.

vitejs/vite#2435 (comment)

I can make a PR to give the warning if you want. Let me know.

@ghostdevv
Copy link
Member

I am confused what the linked comment is involved? Am I missing something? @lamualfa

@lamualfa
Copy link

lamualfa commented Mar 17, 2021

@ghostdevv

In First time when I get this Error, I think the problem came from Vite. Because of that, I try to find the solution about that error and I found the same problem It also happened in the svelte kit.

One of the svelte kit contributor said that the error was caused by Vite. Then the error has been fixed in the latest PR made by the svelte kit contributor to the vite repository.

It's been 2 days since the PR was made the changes haven't been merged. Impatient, I tried to comment on the PR page (That's the link I gave above).

2 days later PR was merged and the latest version of vite was out. I rushed to get the version tested right away on my routify project. After updating, it turns out that the error still occurs.

I was really confused to find out what caused the error. In the end, I tried to dig deeper into the issues that exist in routify repository. And then Voila! I encountered this issue with the exact same case as mine.

I use metatags helper inside .then function.

@jakobrosenberg
Copy link
Member

This has hopefully been fixed in v2.16.0.

For async metatags, use $metatags instead of metatags. This is somewhat experimental, so if you encounter any bugs, please let me know.

@lamualfa
Copy link

lamualfa commented Mar 18, 2021

@jakobrosenberg Is v2.16.0 has been released?

image


I have tried to use it in v2.12.4, but it keeps getting errors.

src/pages/test.svelte

<script>
  import { onMount } from 'svelte';
  import { metatags } from '@roxi/routify';

  onMount(() => {
    new Promise((resolve) => setTimeout(resolve, 3000)).then(() => {
      $metatags.title = 'Hello world';
    });
  });
</script>

<h1>Hello world</h1>

Error

image

@jakobrosenberg
Copy link
Member

@lamualfa https://www.npmjs.com/package/@roxi/routify/v/2.16.0

The store API has only been added in 2.16.0, so it won't work before that.

@lamualfa
Copy link

@jakobrosenberg Oh ok. it looks like the NPM cache has just been updated. I am sorry 😅.

@lamualfa
Copy link

@jakobrosenberg Voila! now it's work in v2.16.0. Thank you very much @jakobrosenberg.

image

@jakobrosenberg
Copy link
Member

Closing this for now then. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants