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

Agx runs lifecycle hooks multiple times #1426

Open
meeroslav opened this issue Oct 29, 2024 · 3 comments
Open

Agx runs lifecycle hooks multiple times #1426

meeroslav opened this issue Oct 29, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@meeroslav
Copy link

Please provide the environment you discovered this bug in.

https://github.com/meeroslav/test-analog/tree/main

Which area/package is the issue in?

Don't know / other

Description

Steps to reproduce:

  • yarn
  • yarn dev
  • navigate to /mounting-test
  • check the inspect -> console
  • notice page was mounted -> unmounted -> mounted, although we only clicked once

Please provide the exception or error you saw

Angular is running in development mode.
mounting-test.agx.ts:13 I am mounting
mounting-test.agx.ts:16 I am unmounting
mounting-test.agx.ts:13 I am mounting


### Other information

_No response_

### I would be willing to submit a PR to fix this issue

- [ ] Yes
- [ ] No
@meeroslav meeroslav added the bug Something isn't working label Oct 29, 2024
@brandonroberts
Copy link
Member

Is this just on first starting up the app in the browser or every time you navigate?

@meeroslav
Copy link
Author

It's happening every time I navigate to that page.

@meeroslav
Copy link
Author

I discovered that the problem is not in the life cycle hook but rather the entire script block being run twice.

For given agx file:

---
title: Mounting test
slug: mounting-test
---

<script lang="ts">
  console.log('__LOADING___________________________');

  onInit(() => {
    console.log('I am mounting (mounting-test)');
  });

  onDestroy(() => {
    console.log('I am unmounting (mounting-test)');
  });
</script>

<template lang="md">
Some template here
</template>

This is the trace in terminal:
image

Notice the loading log happening twice for every navigation.

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