-
Notifications
You must be signed in to change notification settings - Fork 45
Htmx: replace hx-select-oob with body swap + hx-preserve #3634
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
aeaf789
Htmx: replace hx-select-oob machinery with body swap + hx-preserve
reakaleek ff4c467
Htmx: fix boost breaking on non-root-path deployments
reakaleek b0f0247
fix: disable OpenAPI validation to prevent RegexMatchTimeoutException…
Copilot 1c00cf6
Htmx: delete dead provider abstraction
reakaleek ef12313
Htmx: fix preload/guard interaction, finish dead-code cleanup
reakaleek 2e8d783
Nav: stop accumulating expanded folders across navigation
reakaleek 86d533b
Revert "Nav: stop accumulating expanded folders across navigation"
reakaleek dfdb48e
fix: use resolved URL for preload decision, not raw link target (per …
reakaleek 4f0026f
Htmx: anchor loading indicator below the assembler secondary nav
reakaleek b39c75a
Htmx: preserve loading indicator across body swaps
reakaleek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...Elastic.Documentation.Site/Assets/web-components/shared/htmx/strategies/assembler.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { assemblerStrategy } from './assembler' | ||
|
|
||
| // PR previews serve assembler under a prefix like '/elastic/docs-builder/docs/3634' | ||
| // instead of '/docs' — the strategy must key off config.rootPath, not a hardcoded '/docs'. | ||
| jest.mock('../../../../config', () => ({ | ||
| config: { rootPath: '/elastic/docs-builder/docs/3634' }, | ||
| })) | ||
|
|
||
| describe('assemblerStrategy with a non-default rootPath', () => { | ||
| it('treats rootPath-prefixed paths as docs paths', () => { | ||
| expect( | ||
| assemblerStrategy.getPathFromUrl( | ||
| '/elastic/docs-builder/docs/3634/get-started' | ||
| ) | ||
| ).toBe('/elastic/docs-builder/docs/3634/get-started') | ||
| }) | ||
|
|
||
| it('rejects paths outside rootPath', () => { | ||
| expect(assemblerStrategy.getPathFromUrl('/pricing')).toBe(null) | ||
| }) | ||
|
|
||
| it('still excludes the /api sub-app under the prefixed root', () => { | ||
| expect( | ||
| assemblerStrategy.isExternalDocsUrl( | ||
| '/elastic/docs-builder/docs/3634/api/elasticsearch' | ||
| ) | ||
| ).toBe(true) | ||
| }) | ||
|
|
||
| it('accepts absolute self-links on non-elastic.co hosts (previews)', () => { | ||
| // jsdom origin is http://localhost | ||
| expect( | ||
| assemblerStrategy.getPathFromUrl( | ||
| 'http://localhost/elastic/docs-builder/docs/3634/get-started' | ||
| ) | ||
| ).toBe('/elastic/docs-builder/docs/3634/get-started') | ||
| expect( | ||
| assemblerStrategy.getPathFromUrl( | ||
| 'https://some-other-host.dev/elastic/docs-builder/docs/3634/get-started' | ||
| ) | ||
| ).toBe(null) | ||
| }) | ||
| }) |
30 changes: 16 additions & 14 deletions
30
src/Elastic.Documentation.Site/Assets/web-components/shared/htmx/strategies/assembler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,32 @@ | ||
| import { config } from '../../../../config' | ||
| import type { HtmxUrlStrategy } from './types' | ||
|
|
||
| // rootPath is '/docs' on prod but varies on PR previews (e.g. | ||
| // '/elastic/docs-builder/docs/3634'), so it can't be hardcoded. | ||
| const root = config.rootPath.replace(/\/$/, '') | ||
| const apiRoot = `${root}/api` | ||
| const isDocsPath = (path: string) => | ||
| path === root || path.startsWith(`${root}/`) | ||
|
|
||
| export const assemblerStrategy: HtmxUrlStrategy = { | ||
| isExternalDocsUrl: (url) => | ||
| url.startsWith('/docs/api/') || url === '/docs/api', | ||
| url === apiRoot || url.startsWith(`${apiRoot}/`), | ||
|
|
||
| getPathFromUrl: (url) => { | ||
| try { | ||
| if (url.startsWith('/')) return url | ||
| if (url.startsWith('/')) return isDocsPath(url) ? url : null | ||
| const parsed = new URL(url) | ||
| if ( | ||
| parsed.hostname.endsWith('elastic.co') && | ||
| parsed.pathname.startsWith('/docs') | ||
| ) { | ||
| // elastic.co covers canonical links on prod; the origin check | ||
| // covers absolute self-links on previews and white-label hosts. | ||
| const isThisSite = | ||
| parsed.hostname.endsWith('elastic.co') || | ||
| parsed.origin === window.location.origin | ||
| if (isThisSite && isDocsPath(parsed.pathname)) { | ||
| return parsed.pathname | ||
| } | ||
| return null | ||
| } catch { | ||
| return null | ||
| } | ||
| }, | ||
|
|
||
| getFirstSegment: (path) => path.replace('/docs/', '/').split('/')[1] ?? '', | ||
|
|
||
| isSimpleSwapPath: (path) => { | ||
| const normalizedPath = path.endsWith('/') ? path.slice(0, -1) : path | ||
| if (normalizedPath === '/docs') return true | ||
| return path.startsWith('/docs/api/') || path === '/docs/api' | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.