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

Anchor tag respects modifiers #275

Merged
merged 1 commit into from
Apr 16, 2021
Merged

Conversation

stereosteve
Copy link
Contributor

@stereosteve stereosteve commented Apr 14, 2021

Taken from next.js:
https://github.com/vercel/next.js/blob/canary/packages/next/client/link.tsx#L89

Also hijacks the hello-world-src-dir example for testing navigation behavior. This example demonstrates bugs #230 (and maybe also #217) if you:

  • Click About Blank to open in new tab
  • Switch to new tab and hover over Back home
  • index.css stylesheet gets loaded and page appearance changes.

Anyway it would be nice to have an example either in this repo or separate repo that exercises all the navigation + data loading features for testing purposes.

@stereosteve stereosteve requested a review from ije as a code owner April 14, 2021 21:27
@stereosteve
Copy link
Contributor Author

stereosteve commented Apr 14, 2021

I now see that the jsx compiler does ignore links with target="_blank"... so only the modifier keys need to be considered.

Anchor tag emits fetch-page-module event to tell router to preload page assets... but the styles get applied immediately.

applyCSS tries to do some book keeping to add + remove the correct styles, but reloading page or target="_blank" breaks the tracking.

Not sure how to fix yet... but that's what I found so far.

@ije
Copy link
Member

ije commented Apr 15, 2021

@stereosteve nice try! yes the page prefetch will be emitted when mouse over the Anchor component. in your example, i saw the about.css changed the body bg color, and the prefetch will apply this css immediately, it is a right behavior. better import the global styles in the app.tsx instead of pages/*.tsx.

@ije
Copy link
Member

ije commented Apr 15, 2021

can you please move the example to a new folder as examples/anchor-taget?

@stereosteve stereosteve force-pushed the anchor-modified-event branch from ee38ed4 to 45ae2cd Compare April 16, 2021 11:17
Holding ctrl / alt when clicking link defers to default browser behavior.
Also adds a test case to examples dir.

Taken from next.js:
https://github.com/vercel/next.js/blob/canary/packages/next/client/link.tsx#L89
@stereosteve stereosteve force-pushed the anchor-modified-event branch from 45ae2cd to 395ba99 Compare April 16, 2021 11:18
@stereosteve
Copy link
Contributor Author

Ah okay... was confused about intended behavior of CSS loading.
But I learned about <style>{ }</style> component which is much better, so don't have to use css files at all.

Created new examples/anchor-links directory to demonstrate basic navigation features. Switching between Query 0 and Query 1 demonstrates bug #262

@ije
Copy link
Member

ije commented Apr 16, 2021

@stereosteve great! thanks

@ije
Copy link
Member

ije commented Apr 16, 2021

you can you css files fine, or inline-style, or style-components(ssr not support yet), or tailwindcss, or other

@ije ije merged commit f963e61 into alephjs:master Apr 16, 2021
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

Successfully merging this pull request may close these issues.

2 participants