Skip to content

Commit

Permalink
fix: πŸ› critical path css before elder.js's css
Browse files Browse the repository at this point in the history
Desired output for critical path css is to be: 1. critical path css. 2.
elder.js output css. Because the plugin was using the CSS stack which
always it output after the head (where the elderjs css is added) we had
css specificity issues.
  • Loading branch information
nickreese committed Jul 2, 2021
1 parent a7938b2 commit 8a923d3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/critical-path-css/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,20 @@ const plugin = {

{
hook: 'stacks',
name: 'addCriticalPathCssToCssStack',
description: `If a route has a critical path css file it adds it to the cssStack so it is included. Highest priority because css after it will overwrite the critical path css.`,
name: 'addCriticalPathCssToHeadStack',
description: `If a route has a critical path css file it adds it to the headStack so it is included. Highest priority because css after it will overwrite the critical path css.`,
priority: 100,
run: async ({ plugin, request, cssStack }) => {
run: async ({ plugin, request, headStack }) => {
if (!plugin.internal.disable || !plugin.config.rebuilding) {
const critCss = plugin.internal.criticalPathCss[request.route];
if (critCss) {
cssStack.push({
source: 'hooksjs',
string: critCss,
priority: 100,
headStack.push({
source: 'criticalPathCss',
string: `<style type="text/css">${critCss}</style>`,
priority: 40,
});

return { cssStack };
return { headStack };
} else {
console.error(`No critical path for ${request.route}`);
}
Expand Down

0 comments on commit 8a923d3

Please sign in to comment.