-
Notifications
You must be signed in to change notification settings - Fork 106
fix(tools): correct lightdom css routing, improve trailing slash behavior #2944
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
61e2990
fix(tools): correct lightdom css routing, improve trailing slash beha…
zeroedin b6cfdff
fix(tools): build filePath using elementsDir if not present in demo s…
zeroedin 8511e4b
fix(tools): simplify syntax with a ternary
zeroedin d81d2e1
Merge branch 'main' into fix/tools/lightdom-css-routing
bennypowers 21e0a14
fix(tools): select first part of demoSourceParts for filePath
zeroedin 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,62 @@ const cacheBustingMiddleware: PfeMiddleware = () => async function(ctx, next) { | |
| return next(); | ||
| }; | ||
|
|
||
| /** | ||
| * Redirects both /elements and /elements/ to the root | ||
| * Handles both cases: /elements → / and /elements/ → / | ||
| */ | ||
| const elementsToRootRedirectMiddleware: PfeMiddleware = () => ctx => ctx.redirect('/'); | ||
|
|
||
| /** | ||
| * Ensures trailing slash for component URLs | ||
| * FROM: `/elements/footer` | ||
| * TO: `/elements/footer/` | ||
| * @param config normalized PFE dev server config | ||
| */ | ||
| const ensureTrailingSlashMiddleware: PfeMiddleware = () => (ctx, next) => { | ||
| // Only add trailing slash if path doesn't already end with one | ||
| if (!ctx.path.endsWith('/')) { | ||
| return ctx.redirect(`${ctx.path}/`); | ||
| } | ||
| // If it already ends with slash, continue to next middleware | ||
| return next(); | ||
| }; | ||
|
|
||
| /** | ||
| * Handles lightdom CSS files that are missing the tag name in the path | ||
| * FROM: `elements/pf-jazz-hands-lightdom.css` or `elements/pf-jazz-hands-lightdom-shim.css` | ||
| * TO: `elements/pf-jazz-hands/pf-jazz-hands-lightdom.css` or `elements/pf-jazz-hands/pf-jazz-hands-lightdom-shim.css` | ||
| * @param config normalized PFE dev server config | ||
| */ | ||
| const lightdomShortPathMiddleware: PfeMiddleware = config => (ctx, next) => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this need to be hardcoded at the pfe level? IIRC we don't have lightdom stylesheets here. It would be better to implement this middleware in rhds's wds config |
||
| const { sheetName, suffix } = ctx.params; | ||
| // Extract tag name from sheet name (e.g., "rh-footer-lightdom" -> "rh-footer") | ||
| const tagName = sheetName.replace(/-lightdom$/, ''); | ||
| // Keep the full sheetName including -lightdom part for the redirect | ||
| const redirect = `/${config.elementsDir}/${tagName}/${tagName}-lightdom${suffix ?? ''}.css`; | ||
| if (ctx.path !== redirect) { | ||
| return ctx.redirect(redirect); | ||
| } else { | ||
| return next(); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Handles lightdom CSS files accessed from demo directory | ||
| * FROM: `components/pf-jazz-hands/demo/pf-jazz-hands-lightdom.css` | ||
| * TO: `elements/pf-jazz-hands/pf-jazz-hands-lightdom.css` | ||
| * @param config normalized PFE dev server config | ||
| */ | ||
| const demoLightdomMiddleware: PfeMiddleware = config => (ctx, next) => { | ||
| const { tagName, sheetName, suffix } = ctx.params; | ||
| const redirect = `/${config.elementsDir}/${tagName}/${sheetName}${suffix ?? ''}.css`; | ||
| if (ctx.path !== redirect) { | ||
| return ctx.redirect(redirect); | ||
| } else { | ||
| return next(); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Loads the typescript sources for element declaration source requests | ||
| * This is useful when the typescript build runs in parallel. | ||
|
|
@@ -96,6 +152,10 @@ export function pfeDevServerRouterMiddleware( | |
| const router = new Router(); | ||
| const shim = lightdomShimMiddleware(config); | ||
| const demo = demoSubresourceMiddleware(config); | ||
| const shortPath = lightdomShortPathMiddleware(config); | ||
| const demoLightdom = demoLightdomMiddleware(config); | ||
| const trailingSlash = ensureTrailingSlashMiddleware(config); | ||
| const elementsRedirect = elementsToRootRedirectMiddleware(config); | ||
| return router | ||
| .get('/tools/pfe-tools/environment.js(.js)?', environmentMiddleware(config)) | ||
| .get(`/core/pfe-core/:splatPath*.js`, coreMiddleware(config)) | ||
|
|
@@ -107,5 +167,13 @@ export function pfeDevServerRouterMiddleware( | |
| .get(`/${componentSubpath}/:unprefixedElementSlug/:sheetName-lightdom.css`, shim) | ||
| .get(`/${componentSubpath}/:unprefixedElementSlug/demo/:demoName/:fileName.:ext`, demo) | ||
| .get(`/${componentSubpath}/:unprefixedElementSlug/demo/:fileName.:ext`, demo) | ||
| .get(`/${componentSubpath}/:sheetName-lightdom:suffix.css`, shortPath) | ||
| .get(`/${componentSubpath}/:sheetName-lightdom.css`, shortPath) | ||
| .get(`/${elementsDir}/:tagName/demo/:sheetName-lightdom:suffix.css`, demoLightdom) | ||
| .get(`/${elementsDir}/:tagName/demo/:sheetName-lightdom.css`, demoLightdom) | ||
| .get(`/${componentSubpath}/:unprefixedElementSlug/demo`, trailingSlash) | ||
| .get(`/${componentSubpath}/:unprefixedElementSlug`, trailingSlash) | ||
| .get(`/${componentSubpath}`, elementsRedirect) | ||
| .get(`/${componentSubpath}/`, elementsRedirect) | ||
| .routes(); | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a minor nitpick, but if:
http://localhost:8000/components/jump-links
will add the trailing
/, would it also be worthwhile to add the trailing slash to the other demos as well? eg:Feel free to resolve if this is out of scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the trailing slashes themselves were kinda a nitpick of my own, so why not solve one more case.