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

Reset document.title on component unmount #14789

Closed
ottomated opened this issue Dec 20, 2024 · 1 comment
Closed

Reset document.title on component unmount #14789

ottomated opened this issue Dec 20, 2024 · 1 comment

Comments

@ottomated
Copy link
Contributor

Describe the problem

I expect this example to work. That is, when a component is unmounted that contains the following code:

<svelte:head>
  <title>Title</title>
</svelte:head>

it should reset the document.title to the previous value.

This is particularly relevant when using shallow routing, where rendering a page component manually is recommended.

Describe the proposed solution

Something like

$.head(($$anchor) => {
  const previous_title = $.document.title;
  $.teardown(() => {
    $.document.title = previous_title;
  });
  $.document.title = `title`;
});

I'm not sure whether there would need to be some global queue of titles, i.e.

const title_queue = [];
function set_title(title) {
  render_effect(() => {
    title_queue.push(document.title);
    document.title = title;
    return () => {
      if (title_queue.length === 0) return;
      document.title = title_queue.pop();
    };
  });
}

Importance

would make my life easier

@Rich-Harris
Copy link
Member

dupe of #7656, will be fixed by #14116

@Rich-Harris Rich-Harris closed this as not planned Won't fix, can't repro, duplicate, stale Dec 20, 2024
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

2 participants