Skip to content

Features are de-inited too late on ajax navigation #6437

Closed

Description

@fregante

Description

Context:

In short, the turbo:render event is triggered when the new content is already on the page and observeSelector might have already found it.

The abort controller should be aborted before the new content is added to the page, without reintroducing the issues that #6267 fixed.

How to fix this issue

Properly detect the change of page, for example by using MutationObserver on turbo-frame instead of the turbo:render event:

document.addEventListener('turbo:render', () => {

How to replicate the issue + URL

Hopefully this isn't visible at the moment, but it can be reproed. Paste this into a feature like quick-new-issue

void features.add(import.meta.url, {
	init(signal) {
		console.log('xx: init');
		signal.addEventListener('abort', () => {
			console.log('xx: deinit');
		});
		observe('a', () => {
			console.log('xx: found new');
		}, {signal});
	},
});

Then:

  1. Visit any repo page
  2. Click on another tab

Expected log

xx: init
xx: found new (100)
xx: deinit
xx: init
xx: found new (100)

Current log:

xx: init
xx: found new (100)
xx: found new (50)
xx: deinit
xx: init
xx: found new (50)

Extension version

23.3.2

Browser(s) used

Chrome

Activity

  1. fregante commented on Mar 30, 2023

    @fregante
    MemberAuthor

    Ajax events can be tracked with:

    ['turbo:before-cache',
    'turbo:before-fetch-request',
    'turbo:before-fetch-response',
    'turbo:before-render',
    'turbo:before-stream-render',
    'turbo:before-visit',
    'turbo:click',
    'turbo:frame-load',
    'turbo:frame-render',
    'turbo:load',
    'turbo:reload',
    'turbo:render',
    'turbo:submit-end',
    'turbo:submit-start',
    'turbo:visit',
    ].map(x => document.addEventListener(x, e => console.log(x, document.querySelector('[data-hovercard-type="pull_request"]') ? '✅PR' : '❌noPR', location.pathname)))

    Use:

    1. Visit https://github.com/refined-github/refined-github/issues
    2. Paste the above code in the console
    3. Visit the pull requests tab

    The expectation is that there will be a PR on the page only on turbo:render, but in reality it's already there at turbo:frame-render, with no prior "unload" event that we can listen to.

    Screenshot

    Then with the browser buttons:

    1. Go back
    2. Clear console
    3. Go forward

    This works correctly, and it would allow to use before-render as the unload event (except that the URL is /pulls in every event)

    Screenshot 3

  2. fregante commented on May 9, 2023

    @fregante
    MemberAuthor

    I might have found a related issue:

    Screenshot 16

    Easy repro:

    1. Open PR against non-default branch sandbox#53
    2. Click on the "Files" tab
    3. See conversation-activity-filter
  3. self-assigned this
    on Jun 20, 2024
  4. fregante commented on Jun 20, 2024

    @fregante
    MemberAuthor

    I think listeners/observers could just be removed on the first turbo: event dispatched. The actual issue is likely the CSS features that would remove the body attribute too early and therefore cause a visual breakage until the page is actually changed. If they're covered entirely by addCssFeature I could either:

    • add an additional listener after that first signal abort
    • leave the class behind and be done with it

    I'll try to look into it soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions