Skip to content

Commit

Permalink
fix: reset title element to previous value on removal
Browse files Browse the repository at this point in the history
fixes #7656
  • Loading branch information
dummdidumm committed Nov 2, 2024
1 parent 304d88e commit c9f5147
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ export function TitleElement(node, context) {
context.state
);

const statement = b.stmt(b.assignment('=', b.id('$.document.title'), value));
context.state.init.push(b.stmt(b.call('$.title', value)));

if (has_state) {
const statement = b.stmt(b.assignment('=', b.id('$.document.title'), value));
context.state.update.push(statement);
} else {
context.state.init.push(statement);
}
}
12 changes: 12 additions & 0 deletions packages/svelte/src/internal/client/dom/elements/misc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { teardown } from '../../reactivity/effects.js';
import { hydrating } from '../hydration.js';
import { clear_text_content, get_first_child } from '../operations.js';
import { queue_micro_task } from '../task.js';
Expand Down Expand Up @@ -56,3 +57,14 @@ export function add_form_reset_listener() {
);
}
}

/**
* @param {string} text
*/
export function title(text) {
const previous = document.title;
document.title = text;
teardown(() => {
document.title = previous;
});
}

0 comments on commit c9f5147

Please sign in to comment.